ドキュメントに2つのp
タグがあるとします。 jQueryonMouseOverイベントが発生した場合、2つの異なるエフェクトを呼び出す必要があります。これらの2つのタグにIdを付ける必要がありますか?これらのタグにIDを渡すことなく達成できますか?jquery関数の適用にIdが必要ですか?
0
A
答えて
5
にはがありますが、何かにはid
が含まれていますが、要素を一意に識別するための最良の方法です。
あなたはクラスによって代わりidenfityことができます:セレクタの完全なリストはdocumentationで利用可能です
$("p:eq(2)")
:親での位置によって
$("[src='image.jpg']")
:属性によって
$(".myClass")
を
+0
感謝を参照してください!!どちらの 'p'タグも同じクラスを持っています。段落でクリックイベントが発生すると、さまざまな機能を適用したいと考えています。だから私は両方の段落にIDを付ける必要があると思いますか? – niting112
3
は、要素/要素を選択するには、いくつかの方法があります。
$('.classname')
$('#id')
$('tagname')
$('[attr="value"]')
など
5
$('p:first'); // first p tag
$('p:last'); // last p tag
$('p').eq(1); // exactly the second p tag
3
jQueryのは、あなたがより速く、より簡単にスクリプト記述することができますが、残念ながらそれはあなたが本当のJavaScriptを理解することがないですが。
$("*") //selects all elements.
$(":animated") //selects all elements that are currently animated.
$(":button") //selects all button elements and input elements with type="button".
$(":odd") //selects even elements.
$(":odd") //selects odd elements.$("p") selects all <p> elements.
$("p.intro") //selects all <p> elements with class="intro".
$("p#intro") //selects the first <p> elements with id="intro".
$(this) //Current HTML element
$("p#intro:first") //The first <p> element with id="intro"
$("p:eq(2)") // The third <p> element in the DOM
$(".intro") //All elements with class="intro"
$("#intro") //The first element with id="intro"
$("ul li:first") //The first <li> element of the first <ul>
$("ul li:first-child") //The first <li> element of every <ul>
$("[href]") //All elements with an href attribute
$("[href$='.jpg']") //All elements with an href attribute that ends with ".jpg"
$("[href='#']") //All elements with an href value equal to "#"
$("[href!='#']") //All elements with an href value NOT equal to "#"
$("div#intro .head") //All elements with class="head" inside a <div> element with id="intro"
jQueryの - 選択要素cheat sheet
関連する問題
- 1. それぞれjQuery関数のJavascriptコードが必要ですか?
- 2. JQuery Idは変数である必要があります
- 3. jQuery関数での再利用ID
- 4. jQueryで要素IDをSetTimeout関数に渡すには?
- 5. Jquery IDが適用されます。
- 6. パンダのデータフレームに関数を適用するためにラムダが必要なのはなぜですか?
- 7. the_modified_date()関数の使用に関するヘルプが必要
- 8. jquery delegate()関数の理解に助けが必要
- 9. jqueryモバイルページにIDを適用する
- 10. jquery関数を再適用する
- 11. RUPを適用するにはライセンスが必要ですか?
- 12. PhoneGapにjQueryが必要ですか?
- 13. JQuery Ajax関数でtrue/falseを返す必要がありますか?
- 14. jQuery関数に何を追加する必要がありますか?
- 15. エラー:文字列定数の前にunqualified-idが必要です
- 16. 文字列定数の前にunqualified-idが必要です
- 17. jqueryの関数が同じID
- 18. jQueryのload()関数を使用せずにDIVに外部要素IDをロード
- 19. 親のdiv内の要素の存在に同じjqueryの関数を適用
- 20. なぜcount()関数にパラメータが必要なのですか?
- 21. Expressハンドルバーコールバック関数が必要です
- 22. バックボーンモデルIDは数値である必要がありますか?
- 23. SQLクエリの最適化に関するヘルプが必要
- 24. jQueryの:複数のIDに同じ関数を使用し
- 25. unordered_setsで使用するとstd :: stringにハッシュ関数が必要ですか?
- 26. domにid値を適用し、js関数内で変数に設定する
- 27. 3:jsが適切に必要です
- 28. 関数は何バイト必要ですか?
- 29. APSchedulerには実行する関数が必要ですか?
- 30. Jqueryが必要な依存関係式
は、返信用http://api.jquery.com/category/selectors/ – simon