尝试删除基于innerHTML的父节点 - 无法读取未定义的属性“nodeValue”

时间:2013-08-21 20:37:30

标签: javascript jquery sharepoint hide

我需要删除删除附件的选项。我尝试这样做的函数给了我这个错误:无法读取未定义的属性'nodeValue'

enter image description here

我累了这样做:

function hideDelete (){
    $("a").filter(function () { return $.trim(this.childNodes[0].nodeValue) === "Delete"; }).closest("td").hide();                  
}

HTML:

<td class="ms-propertysheet"><img alt="Delete" src="/_layouts/images/rect.gif">&nbsp;<a tabindex="1" href="javascript:RemoveAttachmentFromServer('{2088EB08-E376-4637-A6F9-35675AF46E35}',1)">Delete</a></td>

1 个答案:

答案 0 :(得分:0)

jQuery的:

$('td a').each(function(){
    var $this = $(this);
    if($this.text() == 'Delete'){
        $this.parent().html('');
    }
});

http://jsfiddle.net/5qprY/