Jquery-selector-universal

提供:Dev Guides
移動先:案内検索

jQuery-ユニバーサルセレクター

説明

汎用セレクターは、ドキュメントで使用可能なすべての要素を選択します。

構文

このセレクタを使用する簡単な構文は次のとおりです-

$('*')

パラメーター

これは、このセレクタで使用されるすべてのパラメータの説明です-

  • *-象徴的な星。

返品

他のjQueryセレクターと同様に、このセレクターも、見つかった要素で満たされた配列を返します。

  • * $( '*')*は、ドキュメントで使用可能なすべての要素を選択します。

次の例では、すべての要素を選択し、背景に黄色を適用します。 このセレクターは、head、bodyなどを含むすべての要素を選択することを理解してください。

<html>
   <head>
      <title>The Selecter Example</title>
      <script type = "text/javascript"
         src = "https://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>

これにより、次の結果が生成されます–