Last active
August 29, 2015 14:03
-
-
Save sagarjadhav/6c2e00b9ece18f468c06 to your computer and use it in GitHub Desktop.
List convert to Select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* List convert to Select */ | |
$('ul').each(function() { | |
var list = $(this), | |
select = $(document.createElement('select')).insertBefore($(this)); | |
select.attr('id','list-id'); | |
$('li', this).each(function() { | |
var ahref = $(this).children('a'), | |
target = ahref.attr('target'), | |
option = $(document.createElement('option')) | |
.appendTo(select) | |
.val(ahref.attr('href')) | |
.html(ahref.html()); | |
if (ahref.attr('class') === 'dlspb-selected') { | |
option.attr('selected', 'selected'); | |
} | |
}); | |
select.change(function() { | |
window.location.href = select.val(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment