简体   繁体   English

如何使用jQuery元素添加额外的html?

[英]How do you add extra html after an element with jQuery?

I'm aware of jQuery's append() which appends html inside the selected element. 我知道jQuery的append()将html附加到所选元素内。 I want to add more html after the selected element. 我想在所选元素之后添加更多html。 For instance: 例如:

<a href="/somewhere/">Somewhere</a>

I want to add the html <h3>Hello</h3> after the above to become: 我想在上面添加html <h3>Hello</h3>成为:

<a href="/somewhere/">Somewhere</a>
<h3>Hello</h3>

How can you achieve that in jQuery? 如何在jQuery中实现?

为了解决您的问题,下面是完整的代码:

$('a[href=desired_url]').after('<h3>Hello</h3>');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM