How do I leave a option
selected via jquery ? I know it's because of its selected
attribute, but I have no idea how to do this.
The following code to illustrate how I was doing:
Session
var sessao = localStorage.getItem('selected');
var nomeSessao = localStorage.getItem('selectedName');
if((sessao*1) >0)
{
$('.optSelecionado').text(nomeSessao);
}
Option Listing
function mapa()
{ $.unblockUI();
var identificador = localStorage.getItem('identificador');
var sessao = localStorage.getItem('selected');
var nomeSessao = localStorage.getItem('selectedName');
$('.optSelecionado').text(nomeSessao);
var url = urlprojeto+"/dispositivo/service/enterprise/apps/mapa.php";
var www = "device="+identificador+"";
var www = get_contents(url,www);
var wwwD = www.dados;
var wwwLen = wwwD.length;
var ts = '<select id="caminho" style="width: 100%;">';
ts+= '<option class="optSelecionado" value=""></option>';
for( s=0; s<wwwLen; s++ )
{
var referencia = wwwD[s].erp_obr_ass_codigo;
var nome = wwwD[s].erp_obr_ass_nome;
var identacao = wwwD[s].identacao;
ts+= '<option value="'+referencia+'" name="'+identacao+'">'+identacao+'</option>';
}
ts+='</select>';
$(".mapa").html(ts);
}
But using text
it doubles my option, I would like to leave a option
with nothing, I tried using the remove()
function to remove the optSelecionado
class, but as I'd like to have a option
on white