tags:

views:

56

answers:

2

Bit tricky to communicate but hope this makes sense.

I have 8 div containers and need to wrap all the even numbers with an extra div using Jquery, the desired effect like so,

<div id="wrapper">
  <div id="content">
    </div></div>

  <div id="content">
    </div>

<div id="wrapper">
  <div id="content">
    </div></div>
+8  A: 
$('div.content:even').wrap('<div class="wrapper"></div>');

Note: I changed id to class since you can't have multiple elements with the same id.

Ken Browning
Thats great this worked perfectly! thank you very much :)
Rob
@Ken: damn iPad takes to long to write code on ;)@Rob: if it's correct please accept Ken's answer
fredrik
Sweet, also worked with id's fyi
Rob
It works for id's as well, yes but as ken pointed out, can't have multiple elements with the same id. It is not valid HTML
Norbert de Langen
A: 

Not sure but something like this maybe:

$('#continer:even').wrap('<div id="wrapper" />');

Also note that this will probably not work to good since the is only allowed one element with the same id. Change it to a class instead. And use '.' instead of '#' in the selector.

Why do you want to do this? Is it a style issue? The it probably can be solved using CSS.

..fredrik

Edit: seems that without the editor one can't post HTML code. Ken's way is the way to do it.

fredrik