1 <!DOCTYPE html>
2 <html 3 head 4 meta charset="utf-8" 5 title></ 6 script type="text/javascript" src="js/jquery-1.7.2.js" script 7 8 $(function(){
9 //jquery
10 });
11 changeColor(a){
12 //changeColor
13 }
14 </15 16 body17 ul class="level-1 yes"18 li ="item-i">Ili19 ="item-ii">II
20 ="level-2 yes"21 ="item-a">A22 ="item-b"B
23 ="level-3"24 ="item-1">125 ="item-2">226 ="item-3">327 ><a href="javascript:;" onclick="changeColor(this);">改变颜色a28 ul29 30 ="item-c">C31 32 33 ="item-iii">III34 35 36 >
$("li.item-1").parent().css("border","3px solid blue");
$("li.item-1").parent(".level-3").css("border","3px solid blue");
$("li.item-1").parent(".level-1").css("border","3px solid blue");
$("li").parent().css("border","3px solid blue");
$("li").parent(".level-2").css("border","3px solid blue");
$("a").parent().parent().parent().css("border","3px solid red");
function changeColor(a){
$(a).parent().parent().parent().css("border","3px solid red");
}
$("li").parent("ul").css("border","3px solid blue");
$("li").parent("ul").css("border","3px solid blue");
var rets = $("li").parent("ul");
rets[0].css("border","3px solid red");
$("li.item-1").parents().css("border","3px solid blue");
$("li.item-1").parents(".yes").css("border","3px solid blue");
function changeColor(a){
$(a).parents(".item-b").css("border","3px solid red");
}
$("li.item-1").parents("ul").css("border","3px solid blue");
$("li.item-1").parents("ul").css("border","3px solid blue");
var rets = $("li.item-1").parents("ul");
rets[0].css("border","3px solid red");
$("li.item-1").parentsUntil().css("border","3px solid blue");
$("li.item-1").parentsUntil(".level-2").css("border","3px solid blue");
$("li.item-1").parentsUntil(".level-2",".level-3").css("border","3px solid blue");
function changeColor(a){
$(a).parentsUntil(".item-b").css("border","3px solid red");
}
$("li.item-1").parentsUntil("ul.level-1").css("border","3px solid blue");
$("li.item-1").parentsUntil("ul.level-1").css("border","3px solid blue");
var parents = $("li.item-1").parentsUntil("ul.level-1");
parents[0].css("border","3px solid red");
$("li.item-1").closest().css("border","3px solid blue");
$("li.item-1").closest("ul.level-2").css("border","3px solid blue");