Set selected using jQuery
Posted
by
Charles Marsh
on Stack Overflow
See other posts from Stack Overflow
or by Charles Marsh
Published on 2010-12-31T22:30:46Z
Indexed on
2011/01/01
0:53 UTC
Read the original article
Hit count: 339
Evening All,
Happy new year! I'm trying to change the selected option within this list.. Its only working for some and not others?
selectedVal will either be Kelly Green, Navy etc...
var selectedVal = $(this).text();
$("#product-variants-option-0 option[text=" + selectedVal+"]").attr("selected","selected") ;
This is the select list:
<select class="single-option-selector" id="product-variants-option-0">
<option value="Gunmetal Heather">Gunmetal Heather</option>
<option value="Kelly Green">Kelly Green</option>
<option value="Navy">Navy</option>
</select>
© Stack Overflow or respective owner