jQuery中prevAll()方法用法实例
本文实例讲述了jQuery中prevAll()方法用法。分享给大家供大家参考。具体分析如下:
此方法查找匹配元素集合之前所有的同辈元素。
同辈元素集合可以通过选择器进行筛选。
语法结构:
$("selector").prevAll(expr)
参数列表:
实例代码:
实例一:
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8">
<metaname="author"content="https://www.nhooo.com/"/>
<title>毛票票</title>
<styletype="text/css">
.father{
 height:200px;
 width:200px;
 border:1pxsolidblue;
}
</style>
<scripttype="text/javascript"src="mytest/jQuery/jquery-1.8.3.js"></script>
<scripttype="text/javascript">
$(document).ready(function(){
 $(".fatherdiv").prevAll().css("color","blue")
})
</script>
</head>
<body>
<divclass="father">
 <p>我是p元素</p>
 <span>我是span元素</span>
 <p>我是p元素</p>
 <div>我是div元素</div>
</div>
</body>
</html>
实例二:
<!DOCTYPEhtml>
<html>
<head>
<metacharset="utf-8">
<metaname="author"content="https://www.nhooo.com/"/>
<title>毛票票</title>
<styletype="text/css">
.father{
 height:200px;
 width:200px;
 border:1pxsolidblue;
}
</style>
<scripttype="text/javascript"src="mytest/jQuery/jquery-1.8.3.js"></script>
<scripttype="text/javascript">
$(document).ready(function(){
 $(".fatherdiv").prevAll("span").css("color","blue")
})
</script>
</head>
<body>
<divclass="father">
 <p>我是p元素</p>
 <span>我是span元素</span>
 <p>我是p元素</p>
 <div>我是div元素</div>
</div>
</body>
</html>
希望本文所述对大家的jQuery程序设计有所帮助。
