sudhakarinfotech
(current)
Run Code
Live Code Editor- Javascript getElementsByTagName
Source Code
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Select Elements by Tag Name</title> </head> <body> <h1>JavaScript Select Elements by Tag Name</h1> <script type="text/javascript"> function displayInfo(){ var totalElements=document.getElementsByTagName("p"); for(var elem in totalElements) { totalElements[elem].style.background = "lightgrey"; totalElements[elem].style.padding = "10px"; totalElements[elem].style.fontSize = "20px"; } } </script> <p>This is a first pragraph eelemetn.</p> <p>This is another paragraph element.</p> <p>Let's use the above concept.</p> <button onclick="displayInfo()">count paragraph</button> </body> </html>
Source Code Output :
Running