html - jQuery 1.8.2 - how do I grab an option from a select with only the text? -


simply put, using this:

<select id="test">     <option value="1">abc</option>     <option value="2">def</option> </select> 

how can use jquery option[value="2"] using "def" - keep in mind using 1.8.2

thank you!

try :contains() selector:

$('#test option:contains("def")') 

fiddle

note :contains() wildcard search. if need exact match, think you'll need iterate or filter options , check text(). here's 1 possibility:

http://jsfiddle.net/yuk2k/

console.log(getoptionbytext('test', 'def'));  function getoptionbytext(id, value) {     return $('#' + id).find('option').filter(function() {        return $(this).text() == value;      }); } 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -