Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery - change a drop down menu to a list

Is there a way to convert a drop down menu to be a list using jquery... so:

<select>
<option>1</option>
<option>2</option>
<option>3</option>
</select>

to

<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>

Thanks

like image 557
Tom Avatar asked Dec 28 '22 05:12

Tom


1 Answers

Just iterate over the <option> elements and create a corresponding <li> for each, then add them to a <ul>, like this: (where #menu is the ID of your drop-down)

var list = $('<ul>');
$('#menu option').each(function() {
  $('<li>').text($(this).text()).appendTo(list);
});
list.appendTo($('body'));

Working example on JSBin

like image 89
casablanca Avatar answered Dec 30 '22 18:12

casablanca