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...
$(function() {
$.fn.EveryWhat = function(arg1) {
var arr = [];
if($.isNumeric(arg1)) {
$.each(this, function(idx, item) {
var newNum = idx + 1;
if(newNum%arg1 == 0)
arr.push(item);
});
}
return this.pushStack(arr, "EveryWhat", "");
}
});
Call EveryWhat()
on the element and put in a number for every element you would like to collect.
$("div").EveryWhat(2).wrapInner('');
wrapinner's quotes should have a properly formatted with a class and closing tag. Stackoverflow prevents me from showing what that looks like but here is a link of a self closing div.
That will wrap every other number that you specified. I'm using jquery 1.8.2. so remember use selector call EveryWhat(3)
and a number for every time. Of course putting it at the bottom of the page or wrapping it in a
$(document).ready(function() {
//place above code here
});
You could use every nth and then .wrapInner('')
for the same results.