Пример:
Создать код html для каждого элемента div.
"HTML"
<span>Hello</span> <div></div> <div></div> <div></div>
"CSS"
.red { color:red; }
"Живой пример 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").html("<span class='red'>Hello <b>Again</b></span>");
});
</script>
</head>
<body class="iframe">
<span>Hello</span>
<div></div>
<div></div>
<div></div>
</body>
</html>
<style>
.red { color:red; }
</style>
Пример:
Создать код html для каждого элемента div, затем немедленно произвести дальнейшие манипуляции со всатвленным html кодом.
"jQuery"
$("div").html("<b>Wow!</b> Such excitement...");
$("div b").append(document.createTextNode("!!!"))
.css("color", "red");
"HTML"
<div></div> <div></div> <div></div>
"CSS"
div { color:blue; font-size:18px; }
"Живой пример 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").html("<b>Wow!</b> Such excitement...");
$("div b").append(document.createTextNode("!!!"))
.css("color", "red");
});
</script>
</head>
<body class="iframe">
<div></div>
<div></div>
<div></div>
</body>
</html>
<style>
div { color:blue; font-size:18px; }
</style>