Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.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 .after()未按预期工作_Jquery_Html_Dom - Fatal编程技术网

Jquery .after()未按预期工作

Jquery .after()未按预期工作,jquery,html,dom,Jquery,Html,Dom,我正在构建一个chrome扩展,我有一段代码,如下所示: $('a').filter(function() { return $(this).html().match(/myexpressionhere/); }).after().append('<img src="myImage" />'); $('a').filter(函数(){ 返回$(this.html().match(/myexpressionhere/); }).after().append(“”); 当我运行代码时

我正在构建一个chrome扩展,我有一段代码,如下所示:

$('a').filter(function() {
return $(this).html().match(/myexpressionhere/);
}).after().append('<img src="myImage" />');
$('a').filter(函数(){
返回$(this.html().match(/myexpressionhere/);
}).after().append(“”);
当我运行代码时,它会像预期的那样将我的图像添加到每个锚链接中。但是,它会将它们添加到链接中,如:

<a ...> yada yada <img src="myImage" /></a>
yada-yada
而不是像我想要的那样在之后:

<a ...> yada yada</a><img src="myImage" />
yada-yada

知道为什么吗?

使用
时。在
之后,将要附加的元素插入括号内:

$('a').filter(function() {
    return $(this).html().match(/myexpressionhere/);
}).after('<img src="myImage" />');
$('a').filter(函数(){
返回$(this.html().match(/myexpressionhere/);
}).在('')之后;