开发者

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);


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜