2013-07-21 30 views
0

我建立一個Chrome擴展和我的代碼是這樣一個塊:。經過()不工作按預期

$('a').filter(function() { 
return $(this).html().match(/myexpressionhere/); 
}).after().append('<img src="myImage" />'); 

當我運行代碼,它增加了我的形象給每個錨鏈接爲它應該。然而,它增加了他們裏面象鏈接:

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

,而不是之後,就像我想:

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

任何想法,爲什麼?

+0

使用insertAfter() – Hushme

回答

1

使用.after,您將要在括號內添加元素:

$('a').filter(function() { 
    return $(this).html().match(/myexpressionhere/); 
}).after('<img src="myImage" />'); 
+0

謝謝主席先生。 :) –