按href属性以父元素为目标,并使用jquery添加内容

按href属性以父元素为目标,并使用jquery添加内容,jquery,html,Jquery,Html,这是我当前的html: <div> <a href="http://example.com">example.com</a> </div> 我需要添加一个新的div作为这个结构的最后一个元素。这就是我想要实现的目标: <div> <a href="http://example.com">example.com</a> </div> <div> added e

这是我当前的html:

<div>
    <a href="http://example.com">example.com</a>
</div>

我需要添加一个新的div作为这个结构的最后一个元素。这就是我想要实现的目标:

<div>
    <a href="http://example.com">example.com</a>
</div>

<div>
    added element
</div>

添加元素
我需要通过href属性来定位它。这是我尝试过的,但不起作用:

jQuery('a[href$="http://example.com"]').parent().append('<div>added element</div>');
jQuery('a[href$='http://example.com“]”).parent().append('added element');

您很接近,但这会将
div
附加到包含锚定的
div

您想在
之后使用
而不是
附加
将其添加到该
div
旁边:

jQuery('a[href$="http://example.com"]').parent().after('<div>added element</div>');
// ----------------------------------------------^
jQuery('a[href$='http://example.com“]”).parent()。在('added element')之后;
// ----------------------------------------------^
现场示例:

jQuery('a[href$='http://example.com“]”).parent()。在('added element')之后