Skip to content

Instantly share code, notes, and snippets.

@paulgrav
Created November 13, 2012 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulgrav/4064930 to your computer and use it in GitHub Desktop.
Save paulgrav/4064930 to your computer and use it in GitHub Desktop.
Swap ul/li for select/option
$(".v5-select").each(function(i,o) {
var first_o = $('h3.select-head',o).text();
console.log(first_o);
$('.select-body', o).replaceWith(function() {
form = $("<form/>");
select = $("<select/>");
form.append(select);
select.attr('style', $(this).attr('style'));
var opt = $("<option selected='selected'/>").text(first_o);
select.append(opt);
$("li",this).each(function(i,p) {
if($(p).attr('class') == 'select-group' ) {
option = $("<optgroup />");
option.attr('label',$('a',p).text());
} else {
option = $("<option />");
option.attr('class', $(p).attr('class'));
option.attr('value',$('a',p).attr('href'))
option.html($('a',p).text());
}
select.append(option);
});
console.log(select);
return form;
})
});
$('.select-head').remove();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment