td is a jQuery variable that references a table cell <td> element. This cell contains a <select> element which contains a number of <option> elements; each has a text and value.
This code returns the value (not text) of the selected option.
td.children().val();
I tried many ways to get the text of the selected option, but non of them work.
td.children().text() This returns the text of all the options of the <select> element.
I filtered it many ways but no result returned at all:
td.children(':selected').text()
td.children('option:selected').text()
td.children('[selected]').text()
td.children('[selected=""]').text()
td.children('option[selected=""]').text()
Since
optionis immediate child ofselectnottdthe functionchildren()will not work. Thus none of your attempted solution worked.You need to use
.find()