PPD
PPD

Reputation: 5900

How to add image in table cell

Hi I want to add image in table cell according to condition in table. I am using dynamic table as follow:

$.get('http://myDomain.com/RIA/topIndiaDetails.asp', function(data)
{    
    console.log("####"+data);

    var up = new Image();
    var down = new Image();

    up.src = "../../jquery.mobile/images/up.png";
    down.src = "../../jquery.mobile/images/down.png"

    substr = data.split('$');

    //alert(substr.length);
    //var theader = '<table border="1">\n';
    //<table id="auditOverview" border="1">
    var theader = '<table border="1" id=\"tableId\">\n';
    var tbody = '';

    for (var out = 1;out<substr.length-1;out++)
    {
        //alert(substr[out]);
        tbody += '<tr>';
        var pra = substr[out].split('|^');
        //alert('pra.length is: '+pra.length);

        for (var i=0;i<pra.length-1;i++)
        {
            tbody += '<td>';

            if (pra[i]=="Red")
            {
                pra[i].append("<img id='theImg' src='../../jquery.mobile/images/down.png'/>");
            }
            else if (pra[i]=="Green")
            {
                pra[i].append("<img id='theImg' src='../../jquery.mobile/images/up.png'/>");
            }
            tbody += pra[i];    
            tbody += '</td>'  
        }
        tbody += '</tr>\n';
    }       
    var tfooter = '</table>';
    document.getElementById('wrapper').innerHTML = theader + tbody + tfooter;       

});

Now I am checking condition as if (pra[i]=="Green") then I want to add image in cell insted of "Green" string and same for Red string. Any help will be appreciated. Thanks in advance.

Upvotes: 1

Views: 9137

Answers (1)

mgraph
mgraph

Reputation: 15338

instead of :

pra[i].append("<img id='theImg' src='../../jquery.mobile/images/up.png'/>");

do

pra[i] = "<img id='theImg' src='../../jquery.mobile/images/up.png'/>";

Upvotes: 2

Related Questions