i have the follow code
$("#tlbQueryConf tr:last").append(
$('<td></td>').append(
$(".ddlFields").clone().attr('id', 'ddlFields-' + conf.id).attr('class', '').val(conf.field)));
So now, what i’m trying to accomplish it’s give the attribute selected to the new element with that value that i selected
i tried like this, but sets the atribute selected to the element and not the item
$(".ddlFields").clone().attr('id', 'ddlFields-' + conf.id).attr('class', '').val(conf.field).attr('selected',true)
the html that result its the follow
<select name="ctl00$ContentPlaceHolder1$ddlFields" id="ddlFields-1" class="">
<option value="1">Prueba</option>
<option value="2">cantidad de fallas</option>
<option value="3">nº</option>
<option value="4">Ciudad</option>
<option value="5">COID</option>
<option value="6">COID_DESC</option>
<option value="7">Creado_EN</option>
<option value="8">DSLAM PROVEEDOR</option>
</select>
Note
even using val() the property selected it’s not set to item
If I understand the question correctly (and correct me if I misunderstood), you want to change the selection of the drop down list?
You can do that like this:
and you can retrieve the selected value like this:
You don’t have to worry about setting the
selectedattribute your self, jquery handles that for you when you set the value of the list.See this duplicate question for more information: Change the selected value of a drop-down list with jQuery