Jump to content

User:Phlsph7/AlphabeticToolbox.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Phlsph7 (talk | contribs) at 16:18, 3 June 2024 (Created page with '// sort the links in the toolbox alphabetically $(document).ready(function() { const toolbox = document.getElementById('p-tb'); const list = toolbox.getElementsByTagName('ul')[0]; const items = Array.from(list.getElementsByTagName('li')); items.sort(function(a, b) { var textA = a.textContent.trim().toUpperCase(); var textB = b.textContent.trim().toUpperCase(); return textA.localeCompare(textB); }); // Remove existing items and append sorted ite...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// sort the links in the toolbox alphabetically
$(document).ready(function() {
	const toolbox = document.getElementById('p-tb');
	const list = toolbox.getElementsByTagName('ul')[0];
	const items = Array.from(list.getElementsByTagName('li'));
	items.sort(function(a, b) {
		var textA = a.textContent.trim().toUpperCase();
		var textB = b.textContent.trim().toUpperCase();
		return textA.localeCompare(textB);
	});

	// Remove existing items and append sorted items
	while (list.firstChild) {
		list.removeChild(list.firstChild);
	}
	items.forEach(function(item) {
		list.appendChild(item);
	});
});