web training room for online courses
Learn JavaScript, Free JavaScript Tutorial for Beginners, Interactive JavaScript Examples

How to use Javascript DOM

Javascript DOM

What is DOM? Document Object Model

DOM is (Document Object Model) an object structure of document, where JavaScript can access each object either by their name, id or css-class .

In JavaScript we can access object by some methods like getElementById, getElementsByName, getElementsByClassName etc.

After accessing the object we can set/reset some properties (like value, innerHTML, innerText ) of that object

Here is an Example, we simply want to change the label of the button below once the button is clicked.

This is how we can access the button DOM using javascript, then write a function and call on button click event

document.getElementById("btnUpdate").value = "Yes, You have clicked";

Now let's look at another example of changing the innerHTML of a DIV using JavaScript DOM

Learning Javascript DOM is Fun!

Click => , Below is the code.

document.getElementById("dvDomTest").innerHTML = "Oh Yes, Learning JavaScript DOM, will use in my Project";

To write anything in document use document.write(string)

<script>
document.write("Javascript DOM easy to work wiith");
</script>

Comment
Name Email Website
Subscribe
 
Learn JavaScript DOM

JavaScript Tutorial

JavaScript DOM Example

Consulting