亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 JQuery 的 find 方法,如何根據“foo”子元素的內容選擇某個 HTML 元素

使用 JQuery 的 find 方法,如何根據“foo”子元素的內容選擇某個 HTML 元素

手掌心 2023-08-21 19:31:30
假設我有如下 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......)


查看完整回答
反對 回復 2023-08-21
  • 1 回答
  • 0 關注
  • 124 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號