Text string from table add to select option with jquery -
i have select option:
<select class="mat"> <option value="0">mat 1</option> </select>
and table:
<table id="mat-table"> <tr> <td>option 1</td> <td>desc</td> </tr> <tr> <td>option 2</td> <td>desc</td> </tr> <tr> <td>option 3</td> <td>desc</td> </tr> </table>
i want jquery copy text 'option 1', 'option 2' table select option , this:
<select class="mat"> <option value="0">option 1</option> <option value="1">option 2</option> <option value="2">option 3</option> </select>
please help.
try this:
$('#mat-table td:first-child').each(function(i) { var $option = $('<option>', { value: }).text(this.textcontent); $('.mat').append($option); });
see fiddle
Comments
Post a Comment