duke duke - 1 year ago 46
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.

Answer Source

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