I have some elements like <a class='link'>click</a>
which are created after clicking on another div ...
<a class='link'>click</a>
?
For now I'm forced to use <a onclick='func()' class='link'>cl开发者_StackOverflow社区ick</a>
... and it's not possible to make something like alert($(this).html())
(which must pop-up the text "click").
Thanks
You could use jQuery's live()
method which will handle events for dynamically added elements.
$('a.link').live('click', function() {
alert( $(this).html() );
});
- http://api.jquery.com/live/
Or you could just bind the click like normal when you create them.
$('<a class="link">click</a>').click(function() {
alert( $(this).html() );
}).insertAfter(someselector);
精彩评论