开发者

Put LI with "active" class first in UL

i have an unordered list like this:

<ul>
  <li class="first"><a href="/nl"><span>Nederlands</span></a></li> 
  <li class="active"><a href="/fr">开发者_开发技巧<span>Français</span></a></li> 
  <li class="last"><a href="/de"><span>Deutch</span></a></li> 
</ul>

I need the LI which has the class "active" to be first in the list nomatter what its original position was. Anyone a suggestions on how to do this with jquery?


Use prependTo:

$('li.active').prependTo('ul');

You should probably give an ID to the ul and use that in the prependTo call.

See jsfiddle.


var $active = $('li.active');
$active.prependTo($active.parent());

reference: .prependTo()

demo: http://www.jsfiddle.net/4yUqL/44/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜