Пример:
Создать новый элемент 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").wrap("<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 смотрите исходный код документа.
"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").wrap("<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>