javascript - How to get option selection from table cell with jquery -
i have table header cell contents this:
<th rowspan="1" colspan="1"> <select> <option value="date" selected="selected">date</option> <option value="number">number</option> </select> </th>
i trying selected value this
var $selectors = $("#mytable thead tr th").each(function(index) { var cell = $(this).html(); console.log ("cell:" + cell.tosource()); var value = cell.options[cell.selectedindex].value; });
but error when try read selected value
typeerror: cell.selectedindex undefined
if dump cell console cell.tosource() above looks this
cell:(new string("<select><option value=\"\"></option><option value=\"date\" selected=\"selected\">date</option><option value=\"number\">number</option></select>"))
i have no idea 'new string' coming from, , if source of problem, or how inside of it. how can selected value?
you can selected value
directly using .val
using jquery
$(function () { $('#mytable thead tr th').each(function () { alert($(this).find("select").val()); }); });
Comments
Post a Comment