Jquery-selector-element-class

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

jQuery-要素クラスセレクター

説明

要素クラスセレクターは、指定された要素のクラスと一致するすべての要素を選択します。

構文

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

$('.classid')

パラメーター

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

  • classid -これはドキュメントで使用可能なクラスIDです。

返品

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

  • * $( '。big')-指定されたクラスID *big を持つすべての要素を選択します。
  • * $( 'p.small')-指定されたクラスID *small を持つすべての段落を選択します。
  • * $( '。big.small')- *big および small のクラスを持つすべての要素を選択します。

次の例では、クラス .big のすべての部門を選択し、その背景に黄色を適用します-

<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 second division only*/
            $(".big").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>

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