+ 1
onclick function() doesn't work...
in the html i code: <h1 id="h1">Hello</h1> <button id="bt1" onclick="click()">A</button> in the js page, i code: function click(){ document.getElementById("h1").innerHTML="World"; } when i click the button, nothing happens... any idea why?
3 ответов
+ 6
Modify your JavaScript code:
window.onload = () => {
// rewrite your code here
}
+ 6
//Actually onclick event is working but function you declared "click" DOM elements have a "click()" method on Which stimulates a mouse click , so making it function namw won't work
//Abou click method
https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/click
+ 1
change id name to bt1 in js code