In Javascript, we can add, delete or edit any HTML element, attributes, values and their corresponding content. DOM stands for Document Object Model that is used in Javascript to represent complete HTML document displayed in web browser.
We can get HTML element in Javascript through following ways
- document.getElementById() - Used to find an element by its id
- document.getElementsByTagName() - Used to find elements by tag name
- document.getElementsByClassName() - Used to find elements by class name
We can change the HTML elements by using-
- element.innerHTML= it change the inner HTML of an element
- element.attribute= change the attribute of an HTML element
- element.setAttribute(attribute,value) -change the attribute of an HTML element
examples->
document.getElementById("abc1").innerHTML="Hello Javascript"; document.getElementById("abc2").src="ABC.jpg";
WE CAN ADD OR DELETE THE html ELEMENTS IN Javascript by using the following ways->
- document.createElement() create an HTML element.
- document.removeChild() remove an HTML element.
- document.appendChild() add an HTML element.
- document.replaceChild() replace an HTML element.
- document.write(text) write into the HTML output stream.
0 Comment(s)