Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67441

How to change color of html in page 2 by clicking the button in page 1

$
0
0
**page1.html**

     <button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
  document.querySelector(".example").style.backgroundColor = "red";
}
</script>
**page2.html**

<h2 class="example">A heading with class="example"</h2>

The background color of the h2 tag with class named example won't change after clicked the button in page 1.


Viewing all articles
Browse latest Browse all 67441

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>