More
It is one of JavaScript HTML methods which is getElementById().
The below example finds an HTML element (with id="sumit"), and change the element content ( innerHTML) to "thank you for visiting".
For example
<!DOCTYPE html>
<html lang="en">
<head>
<title>Teknowize </title>
</head>
<body>
<p id="sumit">welcome to teknowize</p>
<button type="button" onclick='document.getElementById("sumit").innerHTML = "thank you for visiting"'>Click Me!</button>
</body>
</html>
Output
Note:- There is no need to use double quotes so we can also use single quotes to write id name and inner html content.
In the below example the src (source) value of the attribute of a <img> tag is change by JavaScript.
For example
<!DOCTYPE html>
<html>
<head>
<title>teknowize</title>
</head>
<body>
<p>JavaScript can change HTML attribute values.</p>
<button onclick="document.getElementById('sumit').src='pic_bulbon.gif'">Turn on light</button>
<img id="sumit" src="pic_bulboff.gif" style="width:100px">
<button onclick="document.getElementById('sumit').src='pic_bulboff.gif'">Turn off light</button>
</body>
</html>
Output
Using JavaScript we can change the style of an HTML element.
For example
<!DOCTYPE html>
<html>
<head>
<title>teknowize</title>
</head>
<body>
<p id="sumit">JavaScript can change the style of an HTML element.</p>
<button type="button" onclick="document.getElementById('sumit').style.fontSize='35px'">Click Me!</button>
</body>
</html>
Output