Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery selector not working

Tags:

jquery

im having some wierd problems with selecting an element with a class.
in my case i have this AJAX query, that returns some links with the same class. when i click the link an event should happend, but it didn't.

then i tried with makeing it alert when the an element with the class had been clicked, nothing happends, then i try to make a direct link on the page with the same class, now it gives me the alert..

what is happening ? the ajax query checks if the user is online, and does this every 1 minute, the element has the class "friend" and i try to call it by this code:

$('.friend').click(function(){
    alert('clicked');
});

nothing happends with the ones displayed by the ajax request. but it responds to the links put directly onto the site.

like image 736
Flaashing Avatar asked Jul 13 '26 01:07

Flaashing


1 Answers

Try using live:

$('.friend').live('live',function(){
    alert('clicked');
});

It will append that handler to items that exist and items that will exist with that selector.

like image 175
Naftali Avatar answered Jul 15 '26 13:07

Naftali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!