Amar
Amar

Reputation: 895

Make link during dynamically populating the table using Jquery

I want to make the link from during dynamic populating the table using Jquery. I am populating the table data as

trHTML += 
        '<tr><td>'+ value['value1'] +
        '</td> <td>' + value['value2'] + 
        '</td> <td>' + value['value3'] + 
        '</td><td>'.html('<a href="' + "http://www.google.com/" + value['valueLink'] + '">' + "Link" + '</a>')+
        '</td></tr>';

But it gives error

Uncaught TypeError: "</td><td>".html is not a function

Upvotes: 0

Views: 67

Answers (1)

Satpal
Satpal

Reputation: 133403

You don't need to use .html() continue string concatenation.

'</td><td>' + '<a href="' + "http://www.google.com/" + value['valueLink'] + '">' + "Link" + '</a>'+ 

However, I would recommend you to create HTML using jQuery( html, attributes ) method for cleaner approach.

var tr = $("<tr>")
var anchor = $("<a>", {
    "href" : "http://www.google.com/" + value['valueLink'],
    "text" : "Link"
});
var td = $("<td>");
td.append(anchor);

tr.append(td);

Upvotes: 3

Related Questions