javascript - Get text of option before the currently selected option of a dropdown -


i'm working on form need validate textbox field between selected dropdown item, , item before selected.

example dropdown:

<select>select</option>   <option value="57">25</option>   <option value="58">28</option>   <option value="59" selected>30</option>   <option value="60">32</option>   <option value="61">33</option>   <option value="62">35</option> </select> 

given selected item, 59, need jquery give me value previous item, in case 58. note example, values not sequential this.

i can item after selected item in jquery using:

$("#sealshaftsizeid option:selected + option").text(); 

i unable find jquery reverse of that.

you can resolve this:

$("option[selected]").prev().css( "background-color", "red" );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>  <select>    <option>1</option>    <option selected>2</option>    <option>3</option>   </select>


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -