0

I want to change the color of the text using the javascript function but nothing happens when I click on the button. The files are in the same folder.

function click() {
  document.getElementById('test').style.color = "red";
  alert("hello");
}
<p id="test">Hello world</p>
<button type="button" onclick="click()">hello</button>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Dunmol
  • 41
  • 4

1 Answers1

0

You had the logic right, but the naming of the javascript function is the problem.
I'm not sure why, but the click() function is reserved for something else and won't actually call your defined function. If you simply rename your function to something like press() it should actually call your function and change the color of your text

J0R1AN
  • 583
  • 7
  • 10