简体   繁体   中英

Remove div elements using jquery?

Code:

 <div id="wrap">
 <div>Hello</div>
 <H1>world</h1>
 </div>

 <button id='btn'>Delete</button>

I need to remove contents inside div->#wrap on button click. the result should be like

<div id="wrap">
</div>

I tried using

$("#btn").click(function(){
    $( "#wrap" ).remove();
});

Use .html('') or empty() to empty the div

$('#wrap').html('');    //$("#wrap").empty();

remove() will remove it from the DOM.

Demo

* Also fix <H1>world</h1> to <h1>world</h1>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM