I have a javascript function that appends elements into my HTML page. I want to add a function that when a user clicks a button in HTML it will remove the associated HTML content from the page.
$("#keywords").append("<td><img src=\"images/delete.png\" class=\"delete_filter\" /> " + id + "</td>");
The code above is how I am adding elements to the HTML. So in this case when a user clicks the appended image <td><img src=\"images/delete.png\" class=\"delete_filter\" />
will be removed from the HTML.
This is what I have now that isn't working:
$(".delete_filter").click(
function(){
($(this).parent()).remove();
});
$(this).parent()in brackets? Try$(this).parent().remove()instead. Also, can you be more specific than 'isn't working'? What's happening that isn't what you expect? If nothing appears to be happening, are you getting any Javascript errors?