簡體   English   中英

什么是jQuery選擇器,用於在特定div中選擇具有特定類的錨元素

[英]What is the jQuery selector for selecting anchor elements with a particular class in a particular div

我有一些像這樣的代碼,我想在div foo選擇每個具有類status <a>標簽

<div id="foo">
...
<a class = "status"> ... </a>
...
</div>

你可以這樣做$('#foo').find('.status')

選擇器將是:

$("#foo a.status");

試試這個,看這個

$("#foo a.status")

祝好運!

這有效。

$("#foo").find("a.status")

沒有“jQuery選擇器”這樣的東西,你的意思是:

要么CSS選擇器

在這種情況下,答案是div#foo a.statusdiv#foo > a.status (取決於是否有中間容器)

或者jQuery函數

在這種情況下,有幾種方法可以做到:

  • $('div#foo a.status')
  • $('div#foo > a.status')
  • $('div#foo').find('a.status')
  • $('div#foo').children('a.status')

嘗試

$('div#foo > a.status')

它選擇了div #foo的DIRECT子節點的錨點

嘗試這個:

$('div#foo a.status')

文檔在這里

jQuery('#foo')     //select elm with id foo
.find('a.status')  //find anchor with class

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM