Пример:
Создать новый элемент div вокруг всех параграфов.
"HTML"
Hello
cruel
World
"CSS"
div { border: 2px solid blue; }
p { background:yellow; margin:4px; }
"Живой пример 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").wrapAll("<div></div>");
});
</script>
</head>
<body class="iframe">
Hello
cruel
World
</body>
</html>
<style>
div { border: 2px solid blue; }
p { background:yellow; margin:4px; }
</style>
Пример:
Создать заново структуру объектов вокруг объекта span. Учтите всё, что находтися между элементами span не войдёт в структуру, например элемент strong. Пробел так же не войдёт в структру.
"HTML"
<span>Span Text</span> <strong>What about me?</strong> <span>Another One</span>
"CSS"
div { border:2px blue solid; margin:2px; padding:2px; }
p { background:yellow; margin:2px; padding:2px; }
strong { 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(){
$("span").wrapAll("<div><div><em><b></b></em>
</div></div>");
});
</script>
</head>
<body class="iframe">
<span>Span Text</span>
<strong>What about me?</strong>
<span>Another One</span>
</body>
</html>
<style>
div { border:2px blue solid; margin:2px; padding:2px; }
p { background:yellow; margin:2px; padding:2px; }
strong { color:red; }
</style>