|
Slyweb
|
|
|
Пример:
var \$curr = $("#start");
\$curr.css("background", "#f99");
$("button").click(function () {
\$curr = \$curr.prev();
$("div").css("background", "");
\$curr.css("background", "#f99");
});
<div></div> <div></div> <div><span>здесь есть дочерний элемент</span></div> <div></div> <div></div> <div></div> <div id="start"></div> <div></div> <p><button>К предыдущему родительскому элементу</button></p>
div { width:40px; height:40px; margin:10px;
float:left; border:2px blue solid;
padding:2px; }
span { font-size:14px; }
p { clear:left; margin:10px; }
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="http://slyweb.ru/css/commonie7.css"
rel="stylesheet" type="text/css"/>
<script src="jquery-1.3.2.min.js"></script>
<script>
$(document).ready(function(){
var \$curr = $("#start");
\$curr.css("background", "#f99");
$("button").click(function () {
\$curr = \$curr.prev();
$("div").css("background", "");
\$curr.css("background", "#f99");
});
});
</script>
</head>
<body class="iframe">
<div></div>
<div></div>
<div><span>здесь есть дочерний элемент</span></div>
<div></div>
<div></div>
<div></div>
<div id="start"></div>
<div></div>
<p><button>К предыдущему родительскому элементу</button></p>
</body>
</html>
<style>
div { width:40px; height:40px; margin:10px;
float:left; border:2px blue solid;
padding:2px; }
span { font-size:14px; }
p { clear:left; margin:10px; }
</style>
Пример:
<div><span>Hello</span></div> <p class="selected">Hello Again</p> <p>And Again</p>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link href="http://slyweb.ru/css/commonie7.css"
rel="stylesheet" type="text/css"/>
<script src="jquery-1.3.2.min.js"></script>
<script>
$(document).ready(function(){
$("p").prev(".selected").css("background", "yellow");
});
</script>
</head>
<body class="iframe">
<div><span>Hello</span></div>
<p class="selected">Hello Again</p>
<p>And Again</p>
</body>
</html>