I’ve seen on StackOverflow and googling around that the most used way to get the selected text from a <SELECT>
element with jquery is like this
JavaScript
x
2
1
$("#cboId :selected").text()
2
what I have is not the id, but an object. I have an object, say
JavaScript
1
2
1
var myCombo= $("#cboId");
2
coming from an earlier piece of code.
I’ve done like this to get the selected text, but is ugly:
JavaScript
1
2
1
$("#" + myCombo.attr('id') + " :selected").text() ;
2
Is there any cleaner way to do it?
Advertisement
Answer
JavaScript
1
2
1
var selectedText = $(":selected",myCombo).text();
2