Run ❯
Get your
own
website
Result Size:
625 x 565
×
Change Orientation
Save Code
Change Theme, Dark/Light
Go to Spaces
<!DOCTYPE html> <html> <head> <style> .mystyle { width: 300px; height: 50px; text-align: center; background-color: coral; color: white; margin-bottom: 10px; float: left; margin: 8px; } </style> </head> <body> <p>In this example, we search for the first div element in the document. Then, if the div element has an id of "myDIV" - change its font size.</p> <button onclick="myFunction()">Try it</button><br> <div id="myDIV" class="mystyle"> I am a DIV element </div> <div class="mystyle"> I am also DIV element </div> <script> function myFunction() { var x = document.getElementsByTagName("DIV")[0]; if (x.id === "myDIV") { x.style.fontSize = "30px"; } } </script> </body> </html>