jQuery15 元件選取(html元素+CSS ID)+刪除元素

jQuery15 元件選取(html元素+CSS ID)+刪除元素

jQuery15 元件選取(html元素+CSS ID)+刪除元素

 

資料來源http://www.w3school.com.cn/jquery/index.asp

code2html:http://tohtml.com/

 

<!DOCTYPE html>
<html>
<head>
<title>jQuery 元件選取(html元素+CSS ID)+刪除元素</title>
<!--資料來源	http://www.w3school.com.cn/jquery/index.asp-->
<scriptsrc="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
/*HTML+class作為選擇器*/
$("button.empty01").click(function(){
console.log("empty01");
$("#div1").empty();
});
$("button.remove01").click(function(){
console.log("remove01");
$("#div1").remove();
});
});
</script>
</head>
<body>
<buttontype="button"class="empty01">從被選元素中删除子元素-empty()</button>
<buttontype="button"class="remove01">删除被選元素(及其子元素)-remove()</button>
<divid="div1"style="height:100px;width:300px;border:1pxsolidblack;background-color:yellow;">
This is some text in the div.
<p>This is a paragraph in the div.</p>
<p>This is another paragraph in the div.</p>
</div>
</body>
</html>

 

 


發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *