Carson D
Carson D

Reputation: 91

Can't edit recieved PHP data from ajax call

I'm using ajax to get data from a database. The server-side language is PHP. In the PHP file that I'm referencing in the ajax call, I echo a div with database information in it. However, when I recieve the data in the browser, I can't make changes to the data using jQuery. For example, when I try to target a specific element:

$(data).appendTo("#container"); //appending recieved data onto page

$(data).find("#delete-button").click(function() { 
$(this).hide();
}); //trying to hide button within appended data when I click it

it doesn't do anything. Why is it that I can't edit the recieved PHP code?

I was able to recieve the data using the ajax call, but I just can't edit the data I'm recieving using jQuery.

Upvotes: 0

Views: 58

Answers (1)

charlietfl
charlietfl

Reputation: 171679

Wrapping the data string in $() the second time is not targeting what you actually appended previously... it is a new fragment instance only in memory

After the append() you can query the element directly in the dom:

$("#delete-button").click(function() { 
    $(this).hide();
});

Upvotes: 2

Related Questions