-->

Thursday, June 5, 2025

JavaScript Program to Use getElementById – DOM Manipulation in JS with Examples

JS DOM programs collection


 JS program to show the concept of getElementById(DOM)



<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1">

<title>background change</title>

</head>

<body>

<button id="bt1" onclick="colorChange();">click to change the background</button>

<script>

function colorChange()

{

//var id=document.getElementById('bt1');

//OR

document.getElementById('bt1').style.backgroundColor="purple";

}

</script>

</body>

</html>


Output:

JS code to implement DOM in program-document.getelementById()