wrapall

.slice and .wrapall

牧云@^-^@ 提交于 2019-12-01 18:15:53
问题 I'm using a bit of code suggested by a member on stackoverflow and adapted by me to wrap every 3 list items as part of a mega menu. The code is: var lis = $("ul > li"); for(var i = 0; i < ls.length; i+=3) { lis.slice(i, i+3).wrapAll("<div class='new'></div>"); } Unfortunately this will grab child li's from the next parent menu to fill up the 'quota' of 3 li's in a div. This is of course massively messing up my menus. For an example please visit here. Does anyone have any suggestion how I

Wrap HTML with DIV until next H3

*爱你&永不变心* 提交于 2019-11-29 14:47:27
I have the following HTML structure: $('#subgroup a').nextUntil('h3').wrapAll('<div></div>'); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="subgroup"> <h3>Group name #1</h3> <a href="#">Link #1</a> <a href="#">Link #2</a> <h3>Group name #2</h3> <a

Wrap HTML with DIV until next H3

你离开我真会死。 提交于 2019-11-28 08:44:42
问题 I have the following HTML structure: $('#subgroup a').nextUntil('h3').wrapAll('<div></div>'); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div id="subgroup"> <h3>Group name #1</h3> <a href="#">Link #1</a> <a href="#">Link #2</a> <h3>Group name #2</h3> <a href="#">Link #3</a> <a href="#">Link #4</a> </div> I have this flat structure because I want to use jQuery UI's accordion effect. I want to wrap all a elements between the h3 elements. But this

Wrap every 3 divs in a div

十年热恋 提交于 2019-11-26 01:23:56
问题 Is it possible to use nth-child selectors to wrap 3 divs using .wrapAll ? I can\'t seem to work out the correct equation. so... <div> <div></div> <div></div> <div></div> <div></div> <div></div> <div></div> </div> becomes... <div> <div class=\"new\"> <div></div> <div></div> <div></div> </div> <div class=\"new\"> <div></div> <div></div> <div></div> </div> </div> 回答1: You can do it with .slice(), like this: var divs = $("div > div"); for(var i = 0; i < divs.length; i+=3) { divs.slice(i, i+3)

工具导航Map

JSON相关