Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

how to display image in html table uisng jquery

ERUM

New member
Joined
Jun 8, 2007
Messages
551
i have following line of code along with gif image ..it showing all database driven data but not image

any help

Code:
 for (var i = 0; i < data.d.length; i++) {
 
 $("#tbl").append("<tr  bgcolor= lightblue><td>" + (data.d[i].CustomerID) + "</td><td>" + (data.d[i].CompanyName) + "</td>" + "<td> <img  src=" +  "'" + "detail.gif" +"'" + "height=20 width=20>  </td>" +  "</tr>");
 
Last edited:

ERUM

New member
Joined
Jun 8, 2007
Messages
551
solved using this

for (var i = 0; i < data.d.length; i++) {

$("#tbl").append("<tr bgcolor= lightblue><td>" + (data.d.CustomerID) + "</td><td>" + (data.d.CompanyName) + "</td>" + "<td> <img src=" + "'" + "detail.gif" +"'" + "height=50 width=50> </td>" + "</tr>");
 

ERUM

New member
Joined
Jun 8, 2007
Messages
551
I WANT TO open div when href is clicked in loop

Code:
  for (var i = 0; i < data.d.length; i++) {
 
// var newRow =  $("#tbl").append("<tr  bgcolor= lightblue><td>" + (data.d[i].CustomerID) + "</td><td>" + (data.d[i].CompanyName) + "</td>" + "<td> <img   src=" +  "'" + "detail.gif" +"'" +  "id=" + "'" +"imgSmile" +"'" + "height=50 width=50>  </td>" +  "</tr>");
var newRow =  $("#tbl").append("<tr  bgcolor= lightblue><td>" + (data.d[i].CustomerID) + "</td><td>" + (data.d[i].CompanyName) + "</td>" + "<td><a href=#> <img   src=" +  "'" + "detail.gif" +"'" +  "id=" + "'" +"imgSmile" +"'" + "height=50 width=50></a>  </td>" +  "</tr>");

how to do this ..i.e for each row I need to open div whne image is clicked ????????????????????
 

Sherin

New member
Joined
Jul 19, 2019
Messages
32
Try this query
Code:
function(response) {
        var trHTML = '';
        $.each(response, function (i, item) {
            var img1 = '<a href="' + item.url1 + '"><img src="' + item.url1 + '"/></a>';
            var img2 = '<a href="' + item.url2 + '"><img src="' + item.url2 + '"/></a>';

            trHTML += '<tr><td>' + item.score + '</td><td>' + img1 + '</td><td>' + img2 + '</td></tr>';
        });
            // append results to table
            $('#resultsTable').append(trHTML);
      }
 

techgnome

PowerPoster
Joined
May 15, 2002
Messages
32,778
Three things:
1) The amount of quotes you used in your jquery for the image is excessive...
this
Code:
+ "<td> <img src=[B]" + "'" + "detail.gif" +"'" + "[/B]height=50 width=50> </td>" + "</tr>");

should just be:
Code:
+ "<td> <img src=[B]'detail.gif' [/B]height=50 width=50> </td>" + "</tr>");
See how much easier that is to read?

2) There's no need to use 20 question marks when one would have been sufficient. Also, a period would have been more appropriate since it was a statement, not an actual question.

3) Te question about the div and image clicking are a completely different question and should have been in a new thread.

4) Yes, I'm feeling a bit snarky and pedantic today, I haven't had my coffee yet.

5) Yes, I realize that's more tan thee things.

6) No I can't count, I thought that would be obvious by now.

7) Help me! I can't stop making lists.

8) eight s a nice round number, so this will assuage my OCD.


-tg
 
Top