......

How to order html elements by content of a children using JQuery?

I have something like:

......

Deena
...

......

Amanda
I want to order the div.outer using the value of the span.author. So far I managed to code the following: var mylist = $('#outer-wrapper'); var mylist2 = $('#outer-wrapper2'); var listitems = mylist.find('.outer span.author'); listitems.sort(function(a, b) { return $(a).html().toUpperCase().localeCompare($(b).html().toUpperCase()); }) $.each(listitems, function(idx, itm) { mylist2.append(itm); }); The thing is this just adds to #outer-wrapper2 the span items instead of the whole div.outer. How can I make it work how I want? Thanks!
from itm, select the ancestor that you want to move. Note, you don't need the $.each

以上就是How to order html elements by content of a children using JQuery?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » jQuery 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏