Skip to content

Instantly share code, notes, and snippets.

@sagarjadhav
Last active August 29, 2015 14:03
Show Gist options
  • Save sagarjadhav/6c2e00b9ece18f468c06 to your computer and use it in GitHub Desktop.
Save sagarjadhav/6c2e00b9ece18f468c06 to your computer and use it in GitHub Desktop.
List convert to Select
/* 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