Changingb element part 1

Changing Elements
65
1/2









Changing Attributes
Once you have selected the element(s) you want to work with, you can change their attributes.
As we have seen in the previous lessons, we can change the text content of an element using the innerHTML property.
Similarly, we can change the attributes of elements.
For example, we can change the src attribute of an image:<img id="myimg" src="orange.png" alt="" />
<script>
var el = document.getElementById("myimg");
el.src = "apple.png";
</script>
We can change the href attribute of a link:
Practically all attributes of an element can be changed using JavaScript.
Comments
Post a Comment