2

How can I convert an unordered list:

<ul class="sizeSelect dropdown-menu">
    <li value="112">
        <a onclick="setDropdownText(112);">30x30 30" Waist 30" Leg</a>
    </li>
    <li value="51">
        <a onclick="setDropdownText(51);">30x32 30" Waist 32" Leg</a>
    </li>
    <li value="113">
        <a onclick="setDropdownText(113);">32x30 32" Waist 30" Leg</a>
    </li>
</ul>

To a select field:

<select>
    <option>30x30 30" Waist 30" Leg</option>
    <option>30x32 30" Waist 32" Leg</option>
    <option>32x30 32" Waist 30" Leg</option>
</select>

Via jQuery?

Charlie
  • 11,380
  • 19
  • 83
  • 138

1 Answers1

2

Certainly an odd requirement, but the easiest is probably by using replaceWith():

$('.sizeSelect').replaceWith(function() {
    var $select = $('<select>');

    $('li', this).each(function(item) {
        $select.append(new Option($(this).text(), $(this).attr('value')));
    });

    return $select;
});

Demo

Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
  • You can create elements with jQuery pretty easily as well: `$(" – Sampson Mar 03 '14 at 22:01
  • @JonathanSampson I prefer the constructor, shorter too ;-) – Ja͢ck Mar 03 '14 at 22:10