Jquery-selector-element-name

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

jQuery-要素名セレクター

説明

要素セレクターは、Tのタグ名を持つすべての要素を選択します。

構文

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

$('tagname')

パラメーター

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

  • tagname -div、p、em、img、liなどの標準HTMLタグ名

返品

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

  • * $( 'p')-ドキュメント内のタグ名が *p のすべての要素を選択します。
  • * $( 'div')-ドキュメント内のタグ名が *div であるすべての要素を選択します。

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

<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 divisions*/
            $("div").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>

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