Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用jQuery添加指向特定文本的链接,忽略';它已经在一个链接中了_Jquery_Html - Fatal编程技术网

使用jQuery添加指向特定文本的链接,忽略';它已经在一个链接中了

使用jQuery添加指向特定文本的链接,忽略';它已经在一个链接中了,jquery,html,Jquery,Html,我需要将“Express Entry”的所有实例更改为“,忽略链接中已有的任何文本 这就是我所拥有的: $('.news article p').each(function() { var text = $(this).html(); if ( ignore anything wrapped in an <a> tag ) { $(this).html(text.replace('Express Entry', '<a href="https:/

我需要将“Express Entry”的所有实例更改为
,忽略链接中已有的任何文本

这就是我所拥有的:

$('.news article p').each(function() {
    var text = $(this).html();
    if ( ignore anything wrapped in an <a> tag ) {
        $(this).html(text.replace('Express Entry', '<a href="https://www.ackahlaw.com/resources/check-your-express-entry-score">Express Entry</a>'));
    }
});
$('.news article p')。每个(函数(){
var text=$(this.html();
if(忽略包含在“')中的任何内容);
}
});
我尝试过使用contents()和nodeType,但不知道如何使其工作

获取匹配元素集中每个元素的子元素,包括文本和注释节点

您需要通过以下方式进行筛选:

$('.news article p')。每个(函数(){
$('.news article p').contents().each(函数(idx,ele){
if(ele.nodeType==Node.TEXT\u Node){//if TEXT Node。。。。。
var newele=ele.textContent.replace('Express Entry',
'');
$(ele).替换为(newele)
}
});
});

text2快速输入text3

text4 text5快速输入text5

获取匹配元素集中每个元素的子元素,包括文本和注释节点

您需要通过以下方式进行筛选:

$('.news article p')。每个(函数(){
$('.news article p').contents().each(函数(idx,ele){
if(ele.nodeType==Node.TEXT\u Node){//if TEXT Node。。。。。
var newele=ele.textContent.replace('Express Entry',
'');
$(ele).替换为(newele)
}
});
});

text2快速输入text3

text4 text5快速输入text5