简体   繁体   中英

adding a class to HTML using jquery?

I have the following JSFIDDLE , which has a main image and image nav.

I need to wrap a div around the image nav so that i can position it with CSS.

How do i add the class to my HTML?

My Example

the question was not clear to me but you can use wrap

$('img ').wrap('<div class="newClass" />');

http://jsfiddle.net/SgCpq/1/

EDIT

$('img').filter(function(){return $(this).width()===40;})
.wrap('<div class="newClass" />');

http://jsfiddle.net/SgCpq/5/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM