Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>remove() / empty()</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style>.chip{display:inline-block;padding:4px 8px;margin:2px;background:#ffe0b2;border:1px solid #ffb74d;border-radius:12px}</style> </head> <body> <div id="wrap"> <span class="chip">One</span> <span class="chip">Two</span> <span class="chip">Three</span> </div> <p> <button id="removeOne">remove() second</button> <button id="emptyAll">empty() wrap</button> </p> <script> $("#removeOne").on("click", function(){ $("#wrap .chip").eq(1).remove(); }); $("#emptyAll").on("click", function(){ $("#wrap").empty(); }); </script> </body> </html>
Output