jQuery –相邻兄弟选择器示例

青旅半醒 2023-02-15 07:48 20阅读 0赞

jQuery相邻的同级选择器(X + Y)用于选择与“ Y”匹配的紧随其后的元素或下一个元素,即“ X”元素的同级。

例如,

  1. <div class="class1"></div>
  2. <p>I'm class1 sibling #1</p>
  3. <p>I'm class1 sibling #2</p>
  4. <p>I'm class1 sibling #3</p>

是同级关系。 “ $(。class1 + p) ”语句将仅选择值为“ I’m class1 sibling#1 ”的

元素,其余的

元素将被忽略。

## jQuery示例 ##

在此示例中,只有值为“ I’m form siblings#1 – DIV ”的

标记将匹配,因为它是
元素的紧随其后的兄弟对象。



jQuery adjacent sibling selector example










jQuery adjacent sibling selector example









  1. <div class="level1">
  2. <div class="level2">
  3. <label>TextBox 3 (Great GrandChild) : </label><input name="textbox3">
  4. </div>
  5. </div>
  6. <label>TextBox 4 (Child) : </label><input name="textbox4">
  7. </form>
  8. <div> I'm form siblings #1 - DIV</div>
  9. <p> I'm form siblings #2 - P </p>
  10. <div> I'm form siblings #3 - DIV </div>
  11. <p> I'm form siblings #4 - P </p>
  12. </body>
  13. </html>

试试演示

标签: jQuery jQuery选择器

翻译自: https://mkyong.com/jquery/jquery-adjacent-sibling-selector-example/

发表评论

表情:
评论列表 (有 0 条评论,20人围观)

还没有评论,来说两句吧...

相关阅读