Định nghĩa và sử dụng .selector() trong jQuery

.selector(): lấy bộ chọn của thành phần.

Cấu trúc .selector() trong jQuery

Đã được thêm vào từ phiên bản 1.3

.selector()

var d = $("div ul.test li:first-child");
$('p').text(d.selector();

.selector()

Html viết:

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Tiêu đề</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
    var d = $("div ul.test li:first-child");
    $("span").text(d.selector);
});
</script>
</head>

<body>
<div>
    <ul class="test">
        <li>li 01</li>
        <li>li 02</li>
        <li>li 03</li>
        <li>li 04</li>
    </ul>
</div>
<span></span>
</body>
</html>

Hiển thị trình duyệt:

Ta thấy thành phần p đã được chèn vào thành phần div, ngay vị trí đầu tiên.

Viết câu trả lời

Drop Images

0 Bình luận