I´m trying to remove a div with jquery but I don´t know how can I refer to the ID because it´s a PHP var: id=”delete$count”
My Javascript code:
<script type="text/javascript">
function deleteFile(fname,directory)
{
$.ajax({ url: "delete_img.php",
data: {"file":fname,"directory":directory},
type: 'post',
success: function(output) {
alert(output);
$('div').remove();
}
});
}
</script>
My PHP code:
$count=1;
echo '<div class="gallery-item" id="delete$count"></div>';
echo "<div><a class='ico ico-delete' rel='9' rev='2' href='#'onclick='deleteFile(\"$file\",\"$directory\")'>
</a></div>";
$count++;
I think the below will send
delete$countverbatim to the response stream without evaluating$countChange it to
so as for PHP to interpolate
$count.Try then passing this as a third parameter to your function as
and collect its value in a third argument to
and replace
by
$('#' + deletecount).remove();