I am looping through $.each in jquery and getting back data and appending that data to a table like this:
$.each(segment, function (index, innerSegment) {
var tr;
tr = $('<tr/>');
tr.append("<td>" + segment[i].Airline.AirlineName + "</td>");
tr.append("<td>" + segment[i].ArrivalTime + "</td>");
tr.append("<td>" + segment[i].Origin "</td>");
tr.append("<td>" + segment[i].DepartureTime + "</td>");
tr.append("<td>" + segment[i].Destination "</td>");
tr.append("<td>" + segment[i].Duration + "</td>");
tr.append("<td>" + segment[i].publishedFare "</td>");
$('#tableId').append(tr);
}
Now, I am getting back proper data from $.each loop. But all the data is appending one after the another.
I want to append the data something like this in this jsfiddle.https://jsfiddle.net/1pbso9jt/
My table is like this:
<table id="tableId">
<tr>
</tr>
</table>
$.each(segment, function (index, innerSegment) { var tr; tr = $('<tr/>'); tr = $('<tr/>'); tr.append("<td rowspan="4">" + segment[i].Airline.AirlineName + "</td>"); tr.append("<td>" + segment[i].ArrivalTime + "</td>"); tr.append("<td>" + segment[i].Origin "</td>"); tr.append("<td>" + segment[i].DepartureTime + "</td>"); tr.append("<td>" + segment[i].Destination "</td>"); tr.append("<td rowspan="4">" + segment[i].Duration + "</td>"); tr.append("<td rowspan="4">" + segment[i].publishedFare "</td>"); $('#tableId').append(tr); }$('<tr/>')is not a valid element selector try$('tr')if you really want to append to a table row. Though my suggestion is to append the whole block to your#tableId. E.g.$('#tableId').append('<tr><td>' + segment[i].Airline.AirlineName + '</td></tr>');. For a nicer looking code feel free to add a line break after or before the+, I prefer my code looking like it was pure html.