javascript - Select boxes not getting displayed on iteration -
trying select boxes through loop. 1 item getting displayed.
<table> <tbody id="addto_tb"></tbody> </table>
var nodeslist = ['node1','node2','node3']; var select = $('<select/>'); $('<option />', {value: 'node1', text: 'node1'}).appendto(select); $('<option />', {value: 'node2', text: 'node2'}).appendto(select); $(nodeslist).each(function(iter,elem){ alert(elem); var trele = $(document.createelement("tr")); trele.addclass(" "+iter); var tdele = $(document.createelement("td")); $(tdele).append(select); trele.append(tdele); $('#addto_tb').append(trele); $($($('#addto_tb').find("."+iter)).find('select')).val(elem); });
in case 3 select boxes should come. 1 displays. when put alert, can see 3 select boxes coming 1 getting displayed. when inspect, can see first 2 <td>
s null.
when create select, there 1 instance of that, each loop, end moving next tr
add .clone() method appending item.
$(tdele).append(select.clone());
Comments
Post a Comment