How to Use JQuery Click Event on Button in an AJAX Form
Posted
by
dpierre23
on Stack Overflow
See other posts from Stack Overflow
or by dpierre23
Published on 2012-09-13T15:29:57Z
Indexed on
2012/09/13
15:38 UTC
Read the original article
Hit count: 453
I admittedly don't know much about JQuery but I have an AJAX page where I need to trigger a click event when someone clicks a button, but because the button is not there on the initial page load, I'm having issues using the click event.
In my code, I just want to run a function when a button is clicked.
<script type="text/javascript">
//Run function when button is clicked
$(document).ready(function() {
$("#idOfButton").click(function() {
doSomething();
});
});
//The function I want ran when page visitor clicks button
function doSomething()
{
//Do Something
}
</script>
Obviously this code doesn't work, but any suggestions on how to use .click? I'm only able to insert JS via a tag management system, so I can't hard code anything into the page. Also, the JQuery version is 1.4, so I can't use .on. Thanks for your help.
© Stack Overflow or respective owner