[jQuery] Dynamic created element doesn't respond to event
Hi,
I have a unordered list with some elements and after some action I add
another element to the list, but it doesn't respond to the click event
set to the list elements.
Example:
Pre existing LIST:
<ul>
<li><a class="clicked">One</a></li>
<li><a class="clicked">Two</a></li>
<li><a class="clicked">Three</a></li>
</ul>
JS click event:
$('a.clicked').click(function(){
alert('clicked');
});
JS dynamic loading:
$(function(){
addElement = function(){
$('ul').append('<li><a class="clicked">Four</a></li>');
}
});
After dynamically loading the last li element, only the first three
respond to the click event. Is this normal behaviour or is there a
workaround or a fix or am i doing something wrong?
Thanks in advance,
Mario