jQuery:如何取得当前元素的父元素的父元素?
发现答非所问的人还不少啊
取父窗口的元素方法:$(selector, window.parent.document);
那么你取父窗口的父窗口的元素就可以用:$(selector, window.parent.parent.document);
类似的,取其它窗口的方法大同小异
$(selector, window.top.document);
$(selector, window.opener.document);
$(selector, window.top.frames[0].document);
希望对你能有帮助
jquery中怎样根据父级找元素?
jquery中parent()可以获取父级元素,所以获得某元素父级的父级可以使用
$(selector).parent().parent();
示例如下
创建Html代码及css样式
class1
class2
class3
div{padding:10px 20px;border:4px solid #ebcbbe;}
div.class1{width:200px;height:120px;}
编写jquery代码
$(function(){
$("div.class3").click(function() {
obj = $(this).parent().parent();
alert(obj.prop('class'));
});
})
Jquery搜索父元素操作方法?
使用js或者jquery查找父元素、子元素经常遇到。可是用起来总容易混淆,这里统一总结了一下,以后用起来相信会方便好多
这里jquery向上查找父元素 用到的方法:
closest() parents() parent()
向下查找子元素
用到的方法:find() children()
js用的是 children[] 属性 !