源代碼
點擊運行
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").remove(); }); }); </script> </head> <body> <div id="div1" style="height:100px;width:300px;border:1px solid black;background-color:yellow;"> 這是 div 中的一些文本。 <p>這是在 div 中的一個段落。</p> <p>這是在 div 中的另外一個段落。</p> </div> <br> <button>移除div元素</button> </body> </html>
運行結果