I am new to JavaScript. I just made this simple script:
[HTML]
<html> <body> <script src="externalscript.js"></script> <p id="text">This text will change style</p><br> <button type="button" onclick="changeStyle()">Click me</button> </body> </html>
[Js code]
function changeStyle() { status = 1; x = document.GetElementById("text"); if(status==1) { x.style.color = 'blue'; status = 2; } if(status==2) { x.style.color = 'red'; status = 3; } if(status==3) { x.style.color = 'yellow'; status = 1; } }
I want him to change the text to a different style every time a button is pressed. However, this does not work. Can someone explain a way to do this correctly?
source share