Мне нравится создавать div для всех изображений в статье, например:
img 1 img 2 img 3
Результат должен быть
<div id="allimg"> img 1 img 2 img 3 </div>
jQuery предоставляет очень полезную функцию wrapAll для вас:
wrapAll
$('img').wrapAll('<div id="allImg"></div>');
Вот один из способов:
$images = $('.articleWrapper img'); // get all the images into a jQuery object $('#allimg').append($images.clone()); // add a copy of them to your div $images.remove(); // remove the originals from the DOM
Не предполагая ничего о макете вашей страницы:
var $i = $('img').first(); // Find the first image: var $d = $('<div>').insertBefore($i); // Create the new div before the first image $('img').appendTo($d); // Move all images into `$d`
Демо на http://jsfiddle.net/alnitak/54kQk/
РЕДАКТИРОВАТЬ Оказывается, это более или менее реализация .wrapAll().
.wrapAll()