dbomb101
dbomb101

Reputation: 423

Wrapping multiple created elements with .wrapAll

the first object selected is not being recognized, but the remainder are

$(links).next(date).next(breakline).andSelf().wrapAll('<span class="mangaLine">');

Upvotes: 0

Views: 300

Answers (2)

RoToRa
RoToRa

Reputation: 38431

I'm not quite sure I understand what you want, and it may depend on your exact HTML structure and sectors, but I think you need to add an additional andSelf() after the first next:

$(links).next(date).andSelf().next(breakline).andSelf().wrapAll('<span class="mangaLine">');

Upvotes: 0

Nick Craver
Nick Craver

Reputation: 630559

You need to include the previous object in the chain as well with another .andSelf() call, like this:

$(links).next(date).andSelf()                  //add links back
        .next(breakline).andSelf()             //add dates and links back
        .wrapAll('<span class="mangaLine">');

.andSelf() only adds the .prevObject in the chain, it can't hop back more than one step, so you need to get the chain before as well. There are a few work-arounds with chaining, I just did that I thought looked cleanest above.

Upvotes: 1

Related Questions