亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery delete element

With jQuery, you can easily delete existing HTML elements.


Delete elements/content

If you need to delete elements and content, you can generally use the following two jQuery methods:

  • remove() - Removes the selected element (and its child elements)

  • empty() - Removes the child element from the selected element


jQuery remove() method

jQuery remove() method deletes the selected element and its child elements.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="http://libs.baidu.com/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>

Run the program and try it


jQuery empty() method

jQuery empty() method deletes The child elements of the selected element.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("#div1").empty();
  });
});
</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>

Run the program and try it


Filter deleted elements

jQuery remove() method can also be used Accepts a parameter that allows you to filter deleted elements.

This parameter can be any jQuery selector syntax.

The following example deletes all <p> elements of class="italic":

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js">
    </script>
    <script>
        $(document).ready(function(){
            $("button").click(function(){
                $("p").remove(".italic");
            });
        });
    </script>
</head>
<body>
<p>這是一個段落。</p>
<p class="italic"><i>這是class="italic"的段落。</i></p>
<p class="italic"><i>這是class="italic"的段落。</i></p>
<button>移除所有  class="italic" 的 p 元素。</button>
</body>
</html>

Run the program to try it


Continuing Learning
||
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"> </script> <script> $(document).ready(function(){ $("button").click(function(){ $("#div1").empty(); }); }); </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>
submitReset Code