I'm trying to make a button that changes the color of the paragraph elements to a random color whenever an user clicks the button. It doesn't seem to work and my text editor (Brackets) are telling me I made 12 mistakes but I don't really sees it. This is what I wrote towards the end of my webpage:
<button id="button1">Color Changer</button>
</div>
</div>
</div>
<script type="text/javascript" src=script.js></script>
</body>
</html>
This is script.js:
var button1El = document.getElementById("button1");
var paragraphsEl = document.getElementsByTagName("p");
var colorChange = function () {
var r = Math.random() * 255;
var g = Math.random() * 255;
var g = Math.random() * 255;
paragraphsEl.style.color = rgb(r, g, b);
}
button1El.addEventListener("click", colorChange);
Thanks in advance!
Aucun commentaire:
Enregistrer un commentaire