you are correct as to why the new element doesn't work.  Try creating the DOM
element and binding a click event to it.  Then placing where you need to.  

Example:

var yLink = $('<a></a>').attr('href', 'www.yahoo.com').html('click
me').bind('click', clickFunction);

 $("#btn").click(function () {
                $("#outerdiv").append(yLink);
});

function clickFunction() { alert("in here"); return false; }


That should accomplish what you want.  


[EMAIL PROTECTED] wrote:
> 
> 
> 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   in the <div> tag
>  $(document).ready(function(){
> 
>  $("#btn").click(function () {
>               $("#outerdiv").html(' www.yahoo.com click me ');
> });
> $("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  
> doesn't exist so the event is not registered.
> How can i register a event on dynamic content using jquery.
> Thanks a bunch
> Haritha
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Register-click-event-on-dynamically-generated-%3Ca%3E-anchor-tag-tp16351148s27240p16359345.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to