Target the Parent of an Element Using jQuery


每个HTML元素根据继承属性都有父parent元素。

举个例子,h3 元素的父元素是 <div class="container-fluid"><div class="container-fluid">的父元素是 body

jQuery有一个方法叫parent(),它允许你访问指定元素的父元素。

举个例子:让left-well 元素的父元素parent()的背景色变成蓝色。

$("#left-well").parent().css("background-color", "blue")

试试让#target1元素的父元素的背景色变成红色。


用jQuery访问指定元素的父元素

相关文章:

  • 2021-12-17
  • 2022-12-23
  • 2021-12-26
  • 2021-12-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-05-28
  • 2021-12-26
  • 2021-12-26
  • 2021-12-13
  • 2022-02-08
  • 2021-12-26
  • 2022-12-23
相关资源
相似解决方案