本文介绍了我想只排序第一个div文本......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
When click on checkbox, i want ul > li > first div Should be Ascending.
The country div should not be ascending it should remaining as it is.
This code is working but not as per my requirement.
我尝试过:
What I have tried:
<input type="checkbox" name="checkbox-choice-t-61" class="ascsection" id="checkbox-choice-t-6a" value="" />
<ul id="Section">
<li style="border-bottom:1px solid #ddd;">
<span style="display:flex;">
<div id="ui-id-2" tabindex="-1" class="abc sectionname">Section</div>
<div id="syriacname-27" class="syriacSection qoloname">Us</div>
</span>
</li>
<li style="border-bottom:1px solid #ddd;">
<span style="display:flex;">
<div id="ui-id-2" tabindex="-1" class="abc sectionname">Farade</div>
<div id="syriacname-27" class="syriacSection qoloname">NewYork</div>
</span>
</li>
</ul>
#Section .sectionname{
float: left;
margin-left: 10px;
margin-top: 10px;
text-align: left;
width: 50%;
padding-bottom: 7px;
}
#Section .qoloname{
float: right;
margin-right: 10px;
margin-top: 10px;
text-align: right;
width: 50%;
padding-bottom: 7px;
}
Checkbox Click
$(".ascsection").click(function(){
if($(this).is(":checked"))
{
var items = $('#Section li').get();
items.sort(function(a,b){
var keyA = $(a).text();
var keyB = $(b).text();
if (keyA < keyB) return -1;
if (keyA > keyB) return 1;
return 0;
});
var ul = $('#Section');
$.each(items, function(i, li){
ul.append(li);
});
}
});
推荐答案
这篇关于我想只排序第一个div文本......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!