Javascript examples for DOM:Document querySelector
Document querySelector() Method - Get the first <p> element in the document:
<!DOCTYPE html> <html> <body> <p>This is a p element.</p> <p>This is also a p element.</p> <button onclick="myFunction()">Test</button> <script> function myFunction() {//from w ww .ja va 2 s . co m document.querySelector("p").style.backgroundColor = "red"; } </script> </body> </html>