View Single Post
Old 06-27-2011, 10:19 AM   #38
burbleburble
Connoisseur
burbleburble began at the beginning.
 
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
Below a piece of javascript. It is designed to wrap groups of elements, the groups starting each time an element with class="Pattern31" occurs.

This part works fine. But I am tearing my hair out trying to figure out why it rearanges the elements it is wrapping; specificly it moves spans from inside a paragraph to somewhere else outside, including the text.

Code:
$patterns = $(".Pattern31")
for(i=0;i<$patterns.size();i++)
{
  $all = $('*', document.body)
  index = $all.index($patterns[i])
  if(i<$patterns.size() + 1)
  {
    $all.slice(index, $all.index($patterns[i+1])).wrapAll('<div class="chapter" />')
  }
}
true
I'd really appreciate if someone could point out my coding mistake, or suggest a different approach


Edit: (I don't know how to delete a solved question...)
I found a workaround at stackoverflow. The workaround, for some reason, works great; even though it uses the sam wrapAll... (it makes for cleaner, more concise code, too)
Code:
$(".Pattern33").each(function(){$(this).add($(this).nextUntil(".Pattern31")).wrapAll("<div class='chapter' />")})
Credits/Thanks: Scharrels at stackoverflow

Last edited by burbleburble; 06-27-2011 at 10:46 AM.
burbleburble is offline   Reply With Quote