Simple jQuery code snippet to wrap all images on a web page into a div which contains a class for formatting. The jQuery wrap() function can be used to wrap any elements on a page with any html code.

jQuery(document).ready(function($) {
	$("img").each(function() {
		$(this).wrap('<div class="someclass"></div>');
	}
});
Sam Deering Sam Deering
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

No Reader comments

Related books & courses
Available now on SitePoint Premium

Preview for $1