Disable anchor tag which is dynamically created
Hi All,
Is there any way to bind events to dynamic html content.
e.g
I have a div tag and button
<div id="outerdiv" style="z-index:1;"></div>
<button id="btn">Click</button>
when the page loads. On click of button a registered event gets fired
creating a anchor tag <a> in the <div> tag
$(document).ready(function(){
$("#btn").click(function () {
$("#outerdiv").html('<a href="www.yahoo.com">click me</a>');
});
$("a").click(function(){
alert('in here');
return false;
});
});
but the click event registered on $("a") never gets executed. i
believe this happens because, when the page is first loaded <a>
doesn't exist so the event is not registered.
How can i register a event on dynamic content using jquery.
Thanks a bunch
Haritha