Sorting li elements by class with jQuery

﹥>﹥吖頭↗ 提交于 2019-12-05 14:09:42

You missed a . - to select a DOM element with a class you must use . - see the class selector docs

var array = ['element2', 'element1', 'element3'];

$.each(array,function(index,value){
   $('.xyz').append($('.'+value));    // add . here
});​

Alternatively you could add the . to the array

Working example here

I would get the inner HTML of each li into an array, empty the ul of elements, then repopulate the ul with the sorted items of the array created in the first step.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!