How to clear all
s’ contents inside a parent
?

前端 未结 14 1880
面向向阳花
面向向阳花 2020-12-07 10:10

I have a div

which has several child
s.

Example:

<
14条回答
  •  眼角桃花
    2020-12-07 10:51

    Use jQuery's CSS selector syntax to select all div elements inside the element with id masterdiv. Then call empty() to clear the contents.

    $('#masterdiv div').empty();
    

    Using 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.

提交回复
热议问题