Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JQuery: Getting Select Options Label

 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I know the cool old fasioned way of getting to a select element options label:

document.getElementById('modelId').options[document.getElementById('modelId').options.selectedIndex].text

My first question is does JQuery have a built in util function to do this?
My second question is, if not, I've started my own but I can't seem to figure out how to return the value from the custom function:



And then doing something like:

jQuery('#someSelectElement').getSelectedLabel()

is returning 'undefined'.

Thanks for any help.
 
Gregg Bolinger
GenRocket Founder
Ranch Hand
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Figured it out:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic