parent():所有匹配元素的父元素的组合
parents():所有匹配元素的祖先元素(包括父元素)的组合
关键代码如下:
bbb
$(function(){
$("input[type='button']").click(function(){
$("div >b").parent("div").css({//将parent改成parents即可查看到区别
border:"1px red solid"
})
}).click();
})
点击运行,查看运行效果:
测试页* { margin:0; padding:0; }
body { font:12px/20px Tahoma, Geneva, sans-serif; padding:100px 200px; }
ul li { list-style:none; }
img { border:0 none; }
input[type='button'] { width:100px; height:38px; display:block; position:fixed; right:20%; top:50px; font-size:13px; }
h1 { height:35px; padding-bottom:10px; }
div{padding:5px}
$(function(){
$("input[type='button']").click(function(){
$("div >b").parent("div").css({//将parent改成parents即可查看到区别
border:"1px red solid"
})
}).click();
})
parent()、parents()的用法区别
parent():所有匹配元素的父元素的组合
parents():所有匹配元素的祖先元素(包括父元素)的组合
效果如下:将所有匹配元素的的父元素或祖先元素加上1px的border
bbb
提示:你可以先修改部分代码再运行。