假設(shè)我有如下 HTML:<div class="foo-container"> <div class="foo"> <div class="foo-child"> <span>The Important Label</span> </div> </div> <div class="elem-to-manipulate"> <p>I want to manipulate the style in this because it's the sibling of "The Important Label"</p> </div></div>p基于其同級元素具有 text 的事實(shí),我如何定位該元素The Important Label。我得到了類似的東西$('.root').find('.foo > .foo-child > span:contains("The Important Label")')這成功地讓我獲得了span元素。但現(xiàn)在我如何獲取p兄弟中的元素div?有沒有辦法告訴 find 哪個(gè)父母要得到兄弟姐妹?
1 回答

隔江千里
TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊
$('.root').find('.foo:has(> .foo-child > span:contains("The Important Label")) + div > p')
aaa:has(bbb)
檢查是否有匹配的內(nèi)容aaa bbb
,然后才匹配aaa
+
匹配先前匹配元素的下一個(gè)同級元素
(根據(jù)您的用例,您可能會滿意.foo:contains("The Important Label") + div > p
......)
- 1 回答
- 0 關(guān)注
- 119 瀏覽
添加回答
舉報(bào)
0/150
提交
取消