2012-01-03 38 views
-4

次の構文を使用して要素を選択できますが、その他の方法はありますか?私は他者を決定しようとするときに何を探すべきか分からなかった。また、ワイルドカード文字で要素を選択する方法はありますか?jquery要素の選択

//Selection by the element's ID 
    $('#mybutton').on('click', function (e) { 
    alert('mybutton clicked'); 
    }); 

    //Select by the element's css class 
    $('.mybuttonclass').on('click', function (e) { 
    alert('mybutton clicked'); 
    }); 

    //Selection of a tag with name of delete found within a table 
    $('table').on('click','a[name=delete]', function (e) { 
    alert('table link clicked'); 
    }); 

したがって、名前、IDまたはクラスを使用できます。他の方法はありますか? Googleの検索用語やリンクが役立ちます。

EDIT:

私は、マニュアルでのセレクタのページを発見したが、このページは適用とは思いませんでした。私はそのページを理解するのに苦労し、何かを指していると思った。だからこそ、私は別の検索語を探していたのです。なぜなら、すべてが「セレクタ」を持ち出していたからです。それは私が必要としていたものではないと思いました。明らかに私は結局正しい場所にいた。

+1

Google検索用語:[jqueryセレクタ](https://www.google.com/search?q=jquery+selectors&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:unofficial&client= firefox-a)。 – Chad

+0

質問タイトルをgoogleに入力する:[jquery要素の選択](http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=jquery+element+selection) – Dennis

+0

オンになっていると、したがって、動的要素よりもスタック内の永続的な要素で使用する必要があります。私はそれがあなたの質問ではないことを知っている、ちょうどそこにそれを投げる。テーブルが常にページ上にあると仮定して、それがうまくいくと思われる唯一のものが最後のものです。 – MetalFrog

答えて

1
Selector Example  Selects 
    *   $("*")    All elements 
    #id   $("#lastname") The element with id=lastname 
    .class $(".intro") All elements with class="intro" 
    element $("p") All p elements 
    .class.class $(".intro.demo") All elements with the classes "intro" and "demo" 

    :first $("p:first") The first p element 
    :last $("p:last") The last p element 
    :even $("tr:even") All even tr elements 
    :odd $("tr:odd") All odd tr elements 

    :eq(index) $("ul li:eq(3)") The fourth element in a list (index starts at 0) 
    :gt(no) $("ul li:gt(3)") List elements with an index greater than 3 
    :lt(no) $("ul li:lt(3)") List elements with an index less than 3 
    :not(selector)$("input:not(:empty)") All input elements that are not empty 

    :header $(":header") All header elements h1, h2 ... 
    :animated $(":animated") All animated elements 

:contains(text)$(":contains('W3Schools')") All elements which contains the text 
    :empty $(":empty") All elements with no child (elements) nodes 
    :hidden $("p:hidden") All hidden p elements 
    :visible $("table:visible") All visible tables 

    s1,s2,s3 $("th,td,.intro") All elements with matching selectors 

[attribute] $("[href]") All elements with a href attribute 
[attribute=value]$("[href='default.htm']") All elements with a href attribute value equal to "default.htm" 
[attribute!=value]$("[href!='default.htm']") All elements with a href attribute value not equal to "default.htm" 
[attribute$=value]$("[href$='.jpg']") All elements with a href attribute value ending with ".jpg" 

    :input $(":input") All input elements 
    :text $(":text") All input elements with type="text" 
    :password $(":password") All input elements with type="password" 
    :radio $(":radio") All input elements with type="radio" 
    :checkbox $(":checkbox") All input elements with type="checkbox" 
    :submit $(":submit") All input elements with type="submit" 
    :reset $(":reset") All input elements with type="reset" 
    :button $(":button") All input elements with type="button" 
    :image $(":image") All input elements with type="image" 
    :file $(":file") All input elements with type="file" 

    :enabled $(":enabled") All enabled input elements 
    :disabled $(":disabled") All disabled input elements 
    :selected $(":selected") All selected input elements 
    :checked $(":checked") All checked input elements 
+0

これは私が私の最初の検索をしたときに私が期待していたものです。ありがとう@PranayRana –

3

jQueryには多くのセレクタがあります。ここを見てくださいSelectors

1

は、uはそれをチェックアウトする必要がありますjQueryのセレクタで最高のドキュメントを持っています。

+1

正直言って、いいえ。それはセレクタの数が足りなくて、それほど詳細がありません。 – SLaks

+1

正直言って、w3schoolsは[ひどい参照]です(http://w3fools.com/)。なぜjquery [それ自体](http://api.jquery.com/category/selectors/)にリンクしないのですか? – hugomg

+1

正直言って、JQueryを使い始めたばかりの人にとってはこれで十分です。それ以外は「食べ過ぎた料理がたくさんあります」。 –