Universal Selector trong jQuery



Miêu tả

Universal Selector (Bộ chọn tổng thể) trong jQuery chọn tất cả phần tử có sẵn trong tài liệu.

Cú pháp

Sau đây là cú pháp để sử dụng Universal Selector trong jQuery:

$('*')

Tham số

Dưới đây miêu tả các tham số được sử dụng trong Universal Selector:

  • * − Một dấu sao.

Trả về

Giống như bất kỳ selector khác trong jQuery, Selector này cũng trả về một mảng các phần tử được tìm thấy.

Quảng cáo

Ví dụ

  • $('*') Chọn tất cả phần tử có sẵn trong tài liệu.

Ví dụ sau chọn tất cả phần tử và áp dụng màu vàng cho màu nền.

<html>
   <head>
      <title>The Selecter Example</title>
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
   
      <script type="text/javascript" language="javascript">
         $(document).ready(function() {
            /* This would select all the elements */
            $("*").css("background-color", "yellow");
         });
      </script>
		
   </head>
	
   <body>

      <div class="big" id="div1">
         <p>This is first division of the DOM.</p>
      </div>

      <div class="medium" id="div2">
         <p>This is second division of the DOM.</p>
      </div>

      <div class="small" id="div3">
         <p>This is third division of the DOM</p>
      </div>

   </body>
	
</html>

Nó sẽ cho kết quả sau:

Các bài học jQuery khác tại VietJack:


selector_trong_jquery.jsp