简体   繁体   中英

How to dynamically add em tag before img?

I want to put em tag before IMG tag dynamically , the image class is .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,

thanks.

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

您可以使用before()方法。

您需要使用before()

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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