I had a "Sign Out" button on one of the pages of my website, but for some reason, whenever I clicked it, the Jquery function that was supposed to be triggered never was triggered. The button worked on other pages of my website, and I spent a while trying to figure out the issue.
Here's my Jquery code:
$(document).ready(function(){
$("#signOut").on("click", function(){
signout();
});
});
After a bit of debugging, I realized that if I did $("signOut").trigger("click")
in the console, the sign out worked perfectly. The css hover and active were working on the button, so I was extremely confused. Then I found this Jquery button click() function is not working and the solution worked for me. I changed my code to
$("document").on('click', '#signOut', function () {}
and it worked... but my button wasn't dynamically created.
Eventually, I realized that I had duplicated the html code. I had my button created before my php and after my php code (that's why I didn't see it). After I got rid of the duplication, my old code worked well, but I'm still confused as to why it created all these problems and why the dynamically created button solution worked.