JSFiddle - React, Tailwind, and code Playground
JavaScript
var obj = {
id: "countries",
label:"Country",
name:"countries",
type:"select",
options:[
{
"value":"",
"text":"Select Country"
},
{
"value":"in",
"text":"India",
"selected":"true"
},
{
"value":"us",
"text":"United Stated"
},
{
"value":"uk",
"text":"United Kingdom"
},
{
"value":"cn",
"text":"Canada"
}
]
};
var $select = $("<select id='"+obj.id+"' name='"+obj.name+"'/>");
var selected = '';
var generateSelector = function (info){
$.each(obj.options, function(i, ob){
if (ob.hasOwnProperty('selected')) {
selected = ob.value;
}
$select.append('<option value='+ob.value+'>'+ ob.text+'</option>')
})
$('body').append($select);
$('select').val(selected)
}
generateSelector()