通过JQuery替换父DIV下的子项中的Text
我想在以下代码中将“ 访问被拒绝。请登录或注册。 ”的文本更改为“您无权访问” : –
我尝试在Ready Function中使用以下代码,但它无法正常工作。
$("div.messages").text(function () { console.log($(this).text()); return $(this).text().replace("Access denied. Please Login or Register.", "You are not authorized to access"); });
谢谢。
有没有其他方法可以做到这一点? 它给了我错误
Uncaught TypeError: Cannot set property 'nodeValue' of undefined ...
$("div.messages h2") .prop('nextSibling') .nodeValue = "You are not authorized to access";
$("div.messages").contents().filter(function() { return this.nodeType === 3 && $.trim(this.nodeValue) !== ''; }).get(0).nodeValue = "You are not authorized to access";