duke duke - 4 months ago 6x
Javascript Question

how to add img tag in td inside $.each

$.each(segment, function (index, innerSegment)
var tr;
for (var i = 0; i < segment.length; i++) {
tr = $('<tr/>');
tr.append("<td>" + <img src="~/Content/left.jpg"/> + + segment[i].Airline.AirlineName + "</td>");

First thing, i am assiging data from $.each loop to a table.
In the last line as u can see, i am finding it difficult to assign
img src tag in the tr.append tag.

I am missing something in the syntax. please tell me what should i try.


There was a simple problem in showing image in td. Howevere, I have tried all the way to show an image.Finally, this line helped me:

  $.each(segment, function(index, innerSegment) {
  var tr;
  tr = $('<tr/>');
  tr.append('<td><img src="../Content/left.jpg"/>' +
   innerSegment.Airline.AirlineName + "</td>");
     // rest of the code 

Simply Replacing tilde symbol(~) with (..) did the trick for me