admin管理员组文章数量:1022603
I'm trying to simply sort unordered lists when they have the following ID.
The code works in a fiddle perfectly /
but when i try to run it on my site it doesn't work or give me any errors. any ideas?
function sortUL(selector) {
var unsortedList = jQuery(selector);
unsortedList.find('li').sort(function (a, b) {
var upA = jQuery(a).text().toUpperCase();
var upB = jQuery(b).text().toUpperCase();
return (upA < upB) ? -1 : (upA > upB) ? 1 : 0;
}).appendTo(selector);
};
jQuery(document).ready(function () {
sortUL("#sortList");
});
I'm trying to simply sort unordered lists when they have the following ID.
The code works in a fiddle perfectly https://jsfiddle/w19Lbjqt/2/
but when i try to run it on my site it doesn't work or give me any errors. any ideas?
function sortUL(selector) {
var unsortedList = jQuery(selector);
unsortedList.find('li').sort(function (a, b) {
var upA = jQuery(a).text().toUpperCase();
var upB = jQuery(b).text().toUpperCase();
return (upA < upB) ? -1 : (upA > upB) ? 1 : 0;
}).appendTo(selector);
};
jQuery(document).ready(function () {
sortUL("#sortList");
});
Share
Improve this question
edited May 8, 2019 at 21:33
Espi
asked May 8, 2019 at 16:21
EspiEspi
215 bronze badges
4
- How are you trying to run it on your site? Where are you enqueueing it? – WebElaine Commented May 8, 2019 at 16:41
- 3 Open the browser dev tools (press F12 on Chrome or FF), go to "Console" and paste your code. If things work as you want, then your code is not being loaded and you should investigate why. You can also use the dev tools for this (check if your JS file is being loaded on the "network" tab). – Daniel Loureiro Commented May 8, 2019 at 17:33
- I verified my scripts file is for sure being loaded. Its being enqueued from my functions file. Any other ideas? – Espi Commented May 8, 2019 at 18:57
- when trying to add the code to the console directly it does nothing also. no errors. nothing. Page in question (employee.provo.edu/human-resource/job-descriptions/…) – Espi Commented May 8, 2019 at 19:29
1 Answer
Reset to default 0I was able to fix this by adjust my call slightly. instead of using
jQuery(document).ready(function () {
sortUL("#sortList");
});
I used
jQuery(window).on("load", function() {
sortUL("#sortList");
});
seems that either SHOULD have worked, but this worked for me nonetheless
I'm trying to simply sort unordered lists when they have the following ID.
The code works in a fiddle perfectly /
but when i try to run it on my site it doesn't work or give me any errors. any ideas?
function sortUL(selector) {
var unsortedList = jQuery(selector);
unsortedList.find('li').sort(function (a, b) {
var upA = jQuery(a).text().toUpperCase();
var upB = jQuery(b).text().toUpperCase();
return (upA < upB) ? -1 : (upA > upB) ? 1 : 0;
}).appendTo(selector);
};
jQuery(document).ready(function () {
sortUL("#sortList");
});
I'm trying to simply sort unordered lists when they have the following ID.
The code works in a fiddle perfectly https://jsfiddle/w19Lbjqt/2/
but when i try to run it on my site it doesn't work or give me any errors. any ideas?
function sortUL(selector) {
var unsortedList = jQuery(selector);
unsortedList.find('li').sort(function (a, b) {
var upA = jQuery(a).text().toUpperCase();
var upB = jQuery(b).text().toUpperCase();
return (upA < upB) ? -1 : (upA > upB) ? 1 : 0;
}).appendTo(selector);
};
jQuery(document).ready(function () {
sortUL("#sortList");
});
Share
Improve this question
edited May 8, 2019 at 21:33
Espi
asked May 8, 2019 at 16:21
EspiEspi
215 bronze badges
4
- How are you trying to run it on your site? Where are you enqueueing it? – WebElaine Commented May 8, 2019 at 16:41
- 3 Open the browser dev tools (press F12 on Chrome or FF), go to "Console" and paste your code. If things work as you want, then your code is not being loaded and you should investigate why. You can also use the dev tools for this (check if your JS file is being loaded on the "network" tab). – Daniel Loureiro Commented May 8, 2019 at 17:33
- I verified my scripts file is for sure being loaded. Its being enqueued from my functions file. Any other ideas? – Espi Commented May 8, 2019 at 18:57
- when trying to add the code to the console directly it does nothing also. no errors. nothing. Page in question (employee.provo.edu/human-resource/job-descriptions/…) – Espi Commented May 8, 2019 at 19:29
1 Answer
Reset to default 0I was able to fix this by adjust my call slightly. instead of using
jQuery(document).ready(function () {
sortUL("#sortList");
});
I used
jQuery(window).on("load", function() {
sortUL("#sortList");
});
seems that either SHOULD have worked, but this worked for me nonetheless
本文标签: jqueryAuto Sorting List Alphabetically
版权声明:本文标题:jquery - Auto Sorting List Alphabetically 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745511407a2153842.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论