开发者

Add a surrounding div with jQuery?

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="wrapp开发者_如何学Pythoner">
  <div id="content">
    </div></div>


$('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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜