07/01/2019, 14:27
JQuery API: :root Selector
Root Selector sẽ lựa chọn phần tử gốc của tài liệu. Trong HTML thì phần tử gốc luôn luôn là thẻ html . Cú pháp Cú pháp jQuery( ":root" ) Ví dụ Tìm kiếm phần tử gốc của tài liệu: ...
Root Selector sẽ lựa chọn phần tử gốc của tài liệu. Trong HTML thì phần tử gốc luôn luôn là thẻ html.
Cú pháp
Cú pháp
jQuery( ":root" )
Ví dụ
Tìm kiếm phần tử gốc của tài liệu:
Code
RUN
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Học lập trình miễn phí tại code24h.com</title>
<script src="https://code24h.com/cnd/js/jquery/jquery-3.2.1.min.js"></script>
<style>
textarea {
height: 45px;
}
</style>
</head>
<body>
<h1>Học lập trình miễn phí tại code24h.com</h1>
<div id="content"></div>
<hr>
<button onclick="myFunction()">Click vào đây để xem kết quả</button>
<script>
function myFunction(){
$( "<b></b>" ).html( 'Gốc tài liệu là thẻ ' + $( ":root" )[ 0 ].nodeName ).appendTo( "#content" );
}
</script>
</body>
</html>Kết quả:
Tham khảo: jquery.com
Nguồn: code24h.com