I have a div Example: I know this is a You can use .empty() function to clear all the child elements To see the comparison between jquery .empty(), .hide(), .remove() and .detach() follow here http://www.voidtricks.com/jquery-empty-hide-remove-detach/ or Works Fine to remove contents inside a div try them if it help. or
jQuery
related question, but I believe someone might get here expecting a pure Javascript
solution. So, if you were trying to do this using js
, you could use the innerHTML
property and set it to an empty string.document.getElementById('masterdiv').innerHTML = '';
$(document).ready(function () {
$("#button").click(function () {
//only the content inside of the element will be deleted
$("#masterdiv").empty();
});
});
$('#div_id').empty();
$('.div_class').empty();
jQuery('#masterdiv div').html('');
$('.div_parent .div_child').empty();
$('#div_parent #div_child').empty();
$("#masterdiv div[id^='childdiv']").each(function(el){$(el).empty();});
$("#masterdiv").find("div[id^='childdiv']").each(function(el){$(el).empty();});