I have following code on my HTML page.
<div id="dynBtn">
<span>Some content</span>
</div>
I am making an AJAX call that returns the following HTML content (as string):
<button id="bNew">New</button>
I am able to successfully replace the above by executing the following jQuery script from within the successful return of AJAX call:
...
//ajax call
...
success: function(retVal)
{
$("div#dynBtn").replaceWith(retVal);
}
...
I am able to see the 'New' button added on the page. But when I click on it, it does not trigger the corresponding jQuery
$("#bNew).click()function(){
//does not come here.
});
The js file containing this code is definitely loaded - I have confirmed this much.
Any suggestions on how can I make this new button trigger the script after it is dynamically added as above?