开发者

JQuery Sortable Accordion moving to top with code

开发者 https://www.devze.com 2023-02-15 11:42 出处:网络
I am building a sortable accordion with jque开发者_如何学Cry which works perfectly fine but I want it so when someone clicks on on of the items in the accordion and it opens up that it is automaticall

I am building a sortable accordion with jque开发者_如何学Cry which works perfectly fine but I want it so when someone clicks on on of the items in the accordion and it opens up that it is automatically moved to the top of the list without the person having to drag it to the top. Is that possible to code?


You can simply use prepend to move the element to the top of list. The HTML is taken from jQuery UI's demo page, with the addition of this line here that moves the element to the top of the list:

$("#accordion h3").click(function(event) {
    $(this).closest('div').prependTo('#accordion');
});

Have a look at the live demo here: http://jsfiddle.net/4jkvg/1/

0

精彩评论

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