Use .live instead of .click


----- Original Message ----- From: "James" <james.gp....@gmail.com>
To: "jQuery (English)" <jquery-en@googlegroups.com>
Sent: Tuesday, September 08, 2009 4:07 PM
Subject: [jQuery] Re: Can't get attributes from ajax response...



When and where are you appending the click() code? If you're doing it
before the AJAX call, then the click event is not assigned to any new
elements. You'll need to use event delegation or the jquery live()
function. Otherwise, you'd have to call the click binding again.

Another thing to note is that IDs cannot begin with a number according
to standards. Though it might work most of the time, it is not
recommended and may cause issues depending on the browser.

On Sep 7, 4:34 pm, DesignFellow <designfel...@gmail.com> wrote:
Hi ,

I'm making a ajax call using $.ajax
my code is

$.ajax({
type: "POST",
url: "sample.php",
dataType:"html",
data: "name="+$('#name').val(),
success: function(msg){
$('#result').append(msg);
}
});

And the response is

<a href="#" id="1123" class="user-link">User1</a>

When i try to get the Id from the response, it's seems not working..

$('.user-link').click(function(){
alert($(this).attr('id'));

});

And i need to make this work urgently...

Any help will be greatly appreciated...

Thanks in advance...

Reply via email to