Create select tag with parameters in JQUERY

Is it possible to create a select tag with parameters 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? It doesn't work for me.

0


a source to share


2 answers


You are using strings incorrectly. You have double quotes in quoted dubble strings, try this instead, also the string in javascript doesn'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")

      

+2


a source


try it.



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");

      

0


a source







All Articles