I had the following JavaScript code and it worked correctly –
var changeImageButton = document.getElementById("changeImageButton");
changeImageButton.onclick = buttonWasClicked;
‘buttonWasClicked’ is the name of the JavaScript function that gets called when the “changeImageButton” is clicked.
Now, I want to write the same code using JQuery. So I wrote –
$("#changeImageButton").attr("onclick","buttonWasClicked");
But it is not working. What am I doing wrong?
You can achieve this using a few different methods