开发者

Move a .class to a desired position using jquery

one
<div id="2" class="h">two</div>
<div id="3" class="h">three</div>
<div id="4" class="h">4</div>
<div id="5" class="h">5</div>

When I click on 5 I want it to move to t开发者_如何学Che position where id=3 is, using jQuery.

Thanks Jean


First of all, id's cannot start with a number, so I don't know how jQuery will react, but this should do it:

$('#5').click(function() {
    $('.h').eq(1).after($(this));
});

That would move #5 between #2 and #3 when clicked upon.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜