javascript - how to set a value of a dropdown to that value having a class as "selected"-Jquery -
i'm trying set value in dropdown has classname = "selected". here html:
<select style="width:180px;" class="chosen-select" id="range"> <option value="7 days">7days</option> <option value="20days" class="selected">20days</option> <option value="30days">30days</option> </select>
now here im trying work out: js:
$("#range_select").find('option.selected'); //gives me: <option value="20days" class="selected">20days</option>
below psedo code:
if($("#range_select").find('option').hasclass("selected")){ //set value of dropdown "20days" //currently showing default value "7days" }
https://jsfiddle.net/xwo10r7k/
how can achieve this? help!!
use
$("#range").find('option.selected').attr("selected","selected");
updated fiddle https://jsfiddle.net/xwo10r7k/1/
Comments
Post a Comment