Пример:
Добавить класс 'selected' к выбранным элементам.
"HTML"
Hello
and
Goodbye
"CSS"
p { margin: 8px; font-size:16px; }
.selected { color:blue; }
.highlight { background:yellow; }
"Живой пример jQuery"
<!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/jqueryiframe.css"
rel="stylesheet" type="text/css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:last").addClass("selected");
});
</script>
</head>
<body class="iframe">
Hello
and
Goodbye
</body>
</html>
<style>
p { margin: 8px; font-size:16px; }
.selected { color:blue; }
.highlight { background:yellow; }
</style>
Пример:
Добавть классы 'selected' и 'highlight' к выбранным элементам.
"HTML"
Hello
and
Goodbye
"CSS"
p { margin: 8px; font-size:16px; }
.selected { color:red; }
.highlight { background:yellow; }
"Живой пример jQuery"
<!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/jqueryiframe.css"
rel="stylesheet" type="text/css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p:last").addClass("selected highlight");
});
</script>
</head>
<body class="iframe">
Hello
and
Goodbye
</body>
</html>
<style>
p { margin: 8px; font-size:16px; }
.selected { color:red; }
.highlight { background:yellow; }
</style>
Пример:
Добавть классы 'selected' и 'highlight' к выбранным элементам.
"jQuery"
$("div").css("border", "2px solid red") .addClass(function(){ return "div"+$(this).index;});
"HTML"
<div class="div1">Первый div
</div> <div class="div2">Второйdiv
</div>
"CSS"
.div1{background: #cadceb;}
.div2{background: #fef;}
"Живой пример jQuery"
<!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/jqueryiframe.css"
rel="stylesheet" type="text/css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("div").css("border", "2px solid red")
.addClass(function(){
return "div"+$(this).index;});
});
</script>
</head>
<body class="iframe">
<div class="div1">Первый div
</div>
<div class="div2">Второйdiv
</div>
</body>
</html>
<style>
.div1{background: #cadceb;}
.div2{background: #fef;}
</style>