I am trying to execute the following Jquery:
$("button.publish").on("click", function(event) {
alert("hello world");
});
On the following HTML:
<button class="publish" data-id="<?= $article['id'] ?>">Publish</button>
But the code doesn't work, the button does not do anything. In the same script file, if I execute a vanilla JS equivalent, with an onClick on the button, it works (below)
function showDetails(article) {
alert("hello world");
}
I have more Jquery code in the exact same script file that is using the .on() function in the same way and that works fine. Can anyone point me to what is going wrong?
I've also tried the following:
$(document).ready(function() {
$("button.publish").on("click", function(event) {
alert("hello world");
});
}