Reputation: 537
I want to delete a specific div
inside a div
using jQuery. How can I do it? Here is my code:
echo "<div class=\"da-slide\">
<h2>".$OPST."</h2>
<p>".$OPSC."
</p>
<div class=\"da-img\">
<input onclick='SLIDE_EDIT($OPID);' class=\"slideedit\" type=\"button\" value=\"EDIT\">
<input onclick='SLIDE_DELETE($OPID);' class=\"slidelete\" type=\"button\" value=\"DELETE\" >
<input id=\"$OPID\" onclick='SLIDE_HIDE($OPID);' class=\"slidehide\" type=\"button\" value=\"$OPSS\" >
".$OPSI."
</div>
This is my delete script. What i did i just to refresh the page after.
function SLIDE_DELETE(SLIDEID)
{
$.post('insert_home.php',{
SLIDE_DELETE:SLIDEID}).done(function(data){
alert('SLIDE SUCCESSFULLY DELETED');
location.reload();
});
}
Upvotes: 0
Views: 68
Reputation: 388316
It is always better to use jQuery event handlers.
Since you have an inline event handler, pass the clicked element reference to the delete function so that it can be deleted
<input onclick='SLIDE_DELETE($OPID, this);' class=\"slidelete\" type=\"button\" value=\"DELETE\" >
then
function SLIDE_DELETE(SLIDEID, el) {
$.post('insert_home.php', {
SLIDE_DELETE: SLIDEID
}).done(function (data) {
alert('SLIDE SUCCESSFULLY DELETED');
//you may want to delete the da-slide element which contains the delete button
$(el).closest('.da-slide').remove();
//if you just want to remove the delete button
//$(el).remove()
});
}
Upvotes: 1