简体   繁体   中英

JQuery, wrap div around every single div

I´ve got a small script, that should wrap a div "wrap_mod_article" around every single parent div "mod_article".

if ($("body").hasClass("test")) {
    $('#content .mod_article').wrapAll('<div class="wrap_mod_article" />');
}

Right now the script creates one div thats around all divs with the class "mod_article". How is it right to wrap a div "wrap_mod_article" around every div with "mod_article"?

http://jsfiddle.net/1t2a2nr4/2/

If you want a clear div at the bottom inside the wrap_mod_article use:

$('#content .mod_article .wrap_mod_article').append('<div class="clear" />');

The selector takes all .wrap_mod_article inside the .mod_article articles from the content container and appends the div with a class clear .

Update jsfiddle:

http://jsfiddle.net/1t2a2nr4/4/

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