JavaScript DOM

JavaScript DOM

#100DaysOfCode#Day8

·

1 min read

Hey Guys,

Today we are going to learn about basic DOM Manipulation using JavaScript.

.innerText

The inner text is used to assign or change the value of the html element.

<h1 id="num">0</h1>
<button id="increment-btn" onclick=inc()>INCREMENT</button>

*{
  margin:0;
  padding:0;
  box-sizing:border-box;
}
#num{
  margin-left:30px;
}
#increment-btn{
  margin-left:10px;
}

let count=0;
function inc(){
  count+=1;
  document.getElementById("num").innerText=count;
}

We can use the getElementById and do the DOM manipulation.