How to remove an element's content with JQuery?

前端 未结 4 1028
借酒劲吻你
借酒劲吻你 2021-02-18 14:54

Say I have a div and some content inside it.

Content

With JQuery, how do I empty the div without removing the di

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-18 15:32

    If the div has an id, you can do it like this:

    $('#id-of-div').html('');
    

    Or you can do all classes of .class-of-div

    $('.class-of-div').html('');
    

    Or just all divs

    $('div').html('');
    

    EDIT: But empty() (above) would work better.

提交回复
热议问题