I am fairly new to wordpress and am trying to define and call a function but cannot get it to work.
The following code appears in a php file that is called from the
Using OnClick or similar attributes is very poor practice.
Using Javascript Event Listener is a much better way of doing this. Registering an event in a modern way is the unobtrusive way of handling events. Also to register more than one event listener for the target you can call addEventListener() for the same target.
HTML:
Your JavaScript is supposed to look like this:
document.getElementById ("checkAllTopicCheckBoxes").addEventListener ("click", myFunction, false);
function myFunction() {
alert("Hello! I am an alert box!!");
}
HTML attribute (such as Onclick) should be avoided as it concerns the content/structure and behavior are not well-separated, making a bug harder to find.