Javascript examples for DOM:Document querySelector
Document querySelector() Method - Use group selector in querySelector() method
<!DOCTYPE html> <html> <body> <h3>A h3 element</h3> <h2>A h2 element</h2> <script> document.querySelector("h2, h3").style.backgroundColor = "red"; </script>//from w ww . j a v a 2s. com </body> </html>
if the <h3> element is before the <h2>. The <h3> element is the one that will get the red background color.
<!DOCTYPE html> <html> <body> <h3>A h3 element</h3> <h2>A h2 element</h2> <script> document.querySelector("h2, h3").style.backgroundColor = "red"; </script>/*from w w w.ja v a 2 s.c o m*/ </body> </html>