I would like to know why jQuery's .val() function is not setting the value of the <select> control for me after I called replaceWith, but it is working otherwise.
Please see here for a (not) working example.
<select><option>ABC</option><option>DEF</option></select> <input type="button" onclick="ControlOff()" value="Turn Off Control" /> <input type="button" onclick="ControlOn()" value="Turn On Control" /> <input type="button" onclick="Test()" value="Value Setting Test" /> function ControlOff() { $('select').each(function () { $(this).replaceWith('<span class="select-type">' + $(this).val() + '</span>'); }); } function ControlOn() { $('.select-type').each(function () { var selected = $(this).text(); $(this).replaceWith('<select><option>ABC</option><option>DEF</option></select>'); $(this).val(selected); }); } function Test() { $('select').val('DEF'); }
but is it ok just to refer people to my question to jsFiddle- not only is it ok, it's super awsome!valueparameter of theoptionitems, though like<option value='abc'>abc</option>