How to clear all
s’ contents inside a parent
?

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

I have a div

which has several child
s.

Example:

<
14条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-07 10:42

    You can use .empty() function to clear all the child elements

     $(document).ready(function () {
      $("#button").click(function () {
       //only the content inside of the element will be deleted
       $("#masterdiv").empty();
      });
     });
    

    To see the comparison between jquery .empty(), .hide(), .remove() and .detach() follow here http://www.voidtricks.com/jquery-empty-hide-remove-detach/

提交回复
热议问题