JavaScript Manipulating Document Elements
Modification
Most attributes you can set on the HTML elements themselves through HTML can also be accessed and modified through JavaScript.
Code example: text content
<h1>True peace required the presence of justice,not just the absence of conflict.</h1><script>const h1 = document.querySelector("h1")console.log(h1.innerText.length) // 80h1.innerText = "Abc"console.log(h1.innerText.length) // 3</script>
Test yourself
Description
Define a new function with the name
modifyHref
that takes a string parameter url and sets the href attribute
of the
#company
anchor tag element to the specified value.
Tests
- 1
You should define a function named
modifyHref. - 2
modifyHref("https://www.audi.com/")should modify the#companyelement'shrefattribute to"https://www.audi.com/". - 3
modifyHref("https://bmw.com/")should modify the#companyelement'shrefattribute to"https://bmw.com/".
Preview