Пример:
Изменить цвет любого параграфа на красный по событию mouseover.
"HTML"
Только проведи мышью надо мной.
Или надо мной, чтоб увидеть как цвет текста изменится.
"CSS"
p { color:blue; width:200px; font-size:14px; }
"Живой пример 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").mouseover(function () {
$(this).css("color","red");
});
});
</script>
</head>
<body class="iframe">
Только проведи мышью надо мной.
Или надо мной, чтоб увидеть как цвет текста изменится.
</body>
</html>
<style>
p { color:blue; width:200px; font-size:14px; }
</style>
Пример:
Чтобы подсветить слово кликните по нему.
"jQuery"
var words = $("p:first").text().split(" "); var text = words.join("</span> <span>"); $("p:first").html("<span>" + text + "</span>"); $("span").click(function () { $(this).css("background-color","yellow"); });
"HTML"
Once upon a time there was a man who lived in a pizza parlor. This man just loved pizza and ate it all the time. He went on to be the happiest man in the world. The end.
"CSS"
p { color:blue; font-weight:bold; cursor:pointer; }
"Живой пример 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(){
var words = $("p:first").text().split(" ");
var text = words.join("</span> <span>");
$("p:first").html("<span>" + text + "</span>");
$("span").click(function () {
$(this).css("background-color","yellow");
});
});
</script>
</head>
<body class="iframe">
Once upon a time there was a man
who lived in a pizza parlor. This
man just loved pizza and ate it all
the time. He went on to be the
happiest man in the world. The end.
</body>
</html>
<style>
p { color:blue; font-weight:bold; cursor:pointer; }
</style>