简体   繁体   English

如何在img之前动态添加em标签?

[英]How to dynamically add em tag before img?

I want to put em tag before IMG tag dynamically , the image class is .photo. 我想将em标签动态地放在IMG标签之前,图像类为.photo。

<img class="photo" src="image.jpg" />

I want to convert this to 我想将其转换为

<em></em><img class="photo" src="image.jpg" />

using jQuery, I am using the append but its add the em in the img tag, 使用jQuery,我使用的是append,但将其添加到了img标签中,

thanks. 谢谢。

$("img.photo").before("<em>");

您可以使用before()方法。

您需要使用before()

jQuery("img").before("em")

编辑:好的,不需要添加结束标记。

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

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