假設我有如下 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 的事實,我如何定位該元素The Important Label。我得到了類似的東西$('.root').find('.foo > .foo-child > span:contains("The Important Label")')這成功地讓我獲得了span元素。但現在我如何獲取p兄弟中的元素div?有沒有辦法告訴 find 哪個父母要得到兄弟姐妹?
1 回答

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