/ Published in: jQuery

Call the function like this:
getChild('.div ul li',4,'newclass',1,1);
Explain: Get all the li's, on every 4 add "newclass", plus, i want a ".clear" and ".seperator" div (to clear the floats and style the separator properly)
getChild('.div ul li',4,'newclass',1,1);
Explain: Get all the li's, on every 4 add "newclass", plus, i want a ".clear" and ".seperator" div (to clear the floats and style the separator properly)
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(document).ready(function(){ function getChild($class,$pos,$add,$clear,$separator){ $num_divs = $($class).length; $i = 1; for($i; $i <= $num_divs; $i++){ if($i % $pos == 0){ $($class).eq($i-1).addClass($add); if($clear == 1){ $('<div class="clear"></div>').insertAfter($($class).eq($i-1)); } if($separator == 1){ $('<div class="separator"></div>').insertAfter($($class).eq($i-1)); } } } } getChild('.div ul li',4,'newclass',1,1); });
Comments
