Jquery .after()未按预期工作
我正在构建一个chrome扩展,我有一段代码,如下所示: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(“”); 当我运行代码时
$('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/);
}).在('')之后;