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

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元素的父元素的背景色变成红色。



猜你喜欢

转载自blog.csdn.net/qq_37499398/article/details/80422578
今日推荐