Creating a select tag with options in JQUERY


Is it possible to create a select tag with options in JQuery.

            $("<select id="jSelect">
        <option value="1">String</option>
        <option value="2">Number</option>
        <option value="3">Date</option>
    </select>").appendTo(".menu li")

Should this work? Its not working for me.



You're using strings wrong. You have double quotes in dubble quoted strings, try this instead, also string in javascript don't span multiple lines.

    $(' <select id="jSelect">'+
            '<option value="1">String</option>'+
           '<option value="2">Number</option>'+
            '<option value="3">Date</option>'+
    '</select>').appendTo(".menu li")

try this.

var optionList = ["String", "Number" ,  "Date"];
var combo = $("<select>").attr("id", "jSelect");
$.each(optionList, function (j, el1) 
    {
    combo.append("<option>" + el1 + "</option>");
    });
combo.appendTo(".menu li");