html - jQuery Closing Open Tags -
while trying parse xml file table format, jquery keeps closing opening <tr>
tag. there work around this?
<script type="text/javascript"> $(document).ready(function(){ $.ajax({ type: "get", url: "sample-data.xml", datatype: "xml", success: parsexml }); }); function parsexml(xml) { $(xml).find("user").each(function() { var id = "#sortable"; $(id).append("<tr>"); $(id).append("<td>" + $(this).find("name").text() + "</td>"); $(id).append("</tr>"); }); } </script> <table id="table" class="tablesorter"> <thead> <tr> <th>test</th> </tr> </thead> <tbody id="sortable"> </tbody> </table>
this how markup being outputted:
<tr></tr> <td>data</td>
yeah, jquery doesn't work that. try this:
function parsexml(xml) { $(xml).find("user").each(function() { var id = "#sortable"; $(id).append('<tr></tr>'); $(id).find('tr:last').html("<td>" + $(this).find("name").text() + "</td>"); }); }
Comments
Post a Comment