JS DOM programs collection
JavaScript Program to change the color of different paragraphs using getElementsByTagName(DOM)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>color of different paragraphs</title>
</head>
<body>
<p>text1</p>
<p>text2</p>
<p>text3</p>
<p>text4</p>
<button onclick="highlights()">click to highlight the paragraphs</button>
<script>
function highlights()
{
let i;
item=document.getElementsByTagName('p');
for(i=0;i<=3;i++)
{
item[i].style.backgroundColor="orange";
}
}
</script>
</body>
</html>