Document querySelector() Method - Use group selector in querySelector() method - Javascript DOM

Javascript examples for DOM:Document querySelector

Description

Document querySelector() Method - Use group selector in querySelector() method

Demo Code

ResultView the demo in separate window

<!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.

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials