Hi all!
Can someone please advise a good approach to this problem:
On page load, an event handler is added to a page element. For example:
// Javascript
// when page is loaded...
jQuery(document).ready(function) {
// assign this handler to the buttonDiv element...
jQuery("#buttonDiv").click(function() {
// to alert "hello"
alert("hello");
});
}
// HTML 5
<div id="buttonDiv">Click me </div>
This works as expected - GREAT!
But suppose the div#buttonDiv
wasn't present when the document is loaded and is added to the DOM later using Ajax. In this case, the click()
event handler is not added and no alert will be called.
How would one add an event handler to this element without using in-line javascript?
Any suggestions welcome.