I have a div Example: jQuery recommend you use ".empty()",".remove()",".detach()" if you needed delete all element in element, use this code : if you needed delete all element, Use this code: i and jQuery group not recommend for use SET FUNCTION like .html() .attr() .text() , what is that? it's IF YOU WANT TO SET ANYTHING YOU NEED ref :https://learn.jquery.com/using-jquery-core/manipulating-elements/ jQuery's empty() function does just that: clears the master clears all the child Use jQuery's CSS selector syntax to select all Using When you are appending data into div by id using any service or database, first try it empty, like this: The better way is : If all the divs inside that masterdiv needs to be cleared, it this. else, you need to iterate on all the div children of #masterdiv, and check if the id starts with childdiv.
$('#target_id').empty();
$('#target_id').remove();
$('#masterdiv').empty();
div
.$('#masterdiv div').empty();
div
s, but leaves the master intact.div
elements inside the element with id masterdiv
. Then call empty() to clear the contents.$('#masterdiv div').empty();
text('')
or html('')
will cause some string parsing to take place, which generally is a bad idea when working with the DOM. Try and use DOM manipulation methods that do not involve string representations of DOM objects wherever possible.var json = jsonParse(data.d);
$('#divname').empty();
$( ".masterdiv" ).empty();
$('#masterdiv div').html('');
$('#masterdiv div').each(
function(element){
if(element.attr('id').substr(0, 8) == "childdiv")
{
element.html('');
}
}
);