/ Published in: jQuery
This function will insert items into an orders alphabetically (assuming it's already alphabetical). Initially design to make a smooth single page load/save feature that sotred everything in drop down lists, you guessed it, alphabetically. Can simply be modified to work in any sort of layout (ordered lists was just easier for the example)
Example at the link, you can post any questions there too.
Example at the link, you can post any questions there too.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function insert(){ var name = $("input[name='insertvalue']").val(); if(name!=''){ var toinsert = true; $("ol.thelist > li").each(function(){ var item = $(this).html(); if(name.toUpperCase() < item.toUpperCase()){ if(toinsert){ $(this).before('<li>'+name+'</li>'); toinsert = false; } } }); if(toinsert){ $("ol.thelist").append('<li>'+name+'</li>'); } $("input[name='insertvalue']").val('') } }
URL: http://fatfolderdesign.com/202/unimportant/insert-alphabetically-with-jquery