See

http://docs.jquery.com/Frequently_Asked_Questions#Why_doesn.27t_an_event_work_on_a_new_element_I.27ve_created.3F

It contains a couple of workarounds.

- Richard

On Tue, Sep 23, 2008 at 8:03 PM, mario <[EMAIL PROTECTED]> wrote:

>
> 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
>

Reply via email to