I have the following code:
$(this).children("a:eq(0)").append('<img src="'+ (arrowsvar.down[1]) +'" class="' + (arrowsvar.down[0]) + '" style="border:0;" />' );
Now I want to remove last appended element (an image). Please give suggestions.
click(function() { $('. project_images'). remove(); return false; });
To remove elements and content, there are mainly two jQuery methods: remove() - Removes the selected element (and its child elements) empty() - Removes the child elements from the selected element.
In jQuery, in order to remove element and content you can use anyone of the following two jQuery methods: Methods: remove() – It is used to remove the selected element (and its child elements). empty() – It is used to removes the child elements from the selected element.
As an alternative, for those who likes more programmatic ways and syntax:
$('#container-element img').last().remove();
You can use the :last-child selector to find the last appended element, then you can remove it:
$('img:last-child', this).remove(); // get the last img element of the childs of 'this'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With