How To Remove An HTML Element By ID Using jQuery

Published Date Author: , Posted April 12th, 2011 at 7:16:31pm

To remove the element with id equal to removeme:
jQuery("#removeme").remove();

To remove the element with id equal to removeme only if it is empty:
jQuery("#removeme:empty").remove();

To remove all empty DIVs:
jQuery("div:empty").remove();

If it’s not empty, but has whitespace:
if(jQuery.trim(jQuery("#removeme").text()) == "") {
jQuery("#removeme").remove();
}

Original Post: http://stackoverflow.com/questions/527246/use-jquery-to-remove-a-div-with-no-children

No comments as yet.

Leave Your Comment  Leave a comment

All fields marked with "*" are required.