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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -