Jeff Reddy
Jeff Reddy

Reputation: 5670

JQuery Adding link to a table cell

I'm trying to add an a tag to a table cell. My code is working all the way up to the final line shown here, at which point I get an exception of

'TypeError: Object doesn't support this property or method'

From what I've read, appendChild should be a method on my table cell.

    var rowId = "#rowid-" + response.id;
    var actionCell = $('#itemlist').find(rowId).find(actionCellId);
    //Add my Edit link                
    link = document.createElement('a');
    link.setAttribute('href', '/MYSite/Item/Edit?itemID=' + response.id);
    link.setAttribute('id', 'edit-' + response.id);
    var linkText = document.createTextNode('Edit');
    link.appendChild(linkText);
    //Exception occurs on this line
    actionCell.appendChild(link);

Upvotes: 0

Views: 2932

Answers (1)

wanovak
wanovak

Reputation: 6127

Replace this:

link = document.createElement('a');
link.setAttribute('href', '/MYSite/Item/Edit?itemID=' + response.id);
link.setAttribute('id', 'edit-' + response.id);
var linkText = document.createTextNode('Edit');
link.appendChild(linkText);
//Exception occurs on this line
actionCell.appendChild(link);

With this:

$('<a>Edit</a>').attr({
    'href': '/MYSite/Item/Edit?itemID=' + response.id,
    'id': 'edit-' + response.id
}).appendTo(actionCell);

Upvotes: 4

Related Questions