Пример:
Подсчитать элементы div. Чтобы повторить нажмите ещё раз.
"jQuery"
$(document.body).click(function () { $(document.body).append($("<div>>")); var n = $("div").size(); $("span").text("There are " + n + " divs." + "Click to add more."); }).click(); // trigger the click to start
"HTML"
<span></span> <div></div>
"CSS"
body { cursor:pointer; }
div { width:50px; height:30px; margin:5px; float:left;
background:blue; }
span { 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(){
$(document.body).click(function () {
$(document.body).append($("<div>>"));
var n = $("div").size();
$("span").text("There are " + n + " divs." +
"Click to add more.");
}).click(); // trigger the click to start
});
</script>
</head>
<body class="iframe">
<span></span> <div></div>
</body>
</html>
<style>
body { cursor:pointer; }
div { width:50px; height:30px; margin:5px; float:left;
background:blue; }
span { color:red; }
</style>