[英]how can I add html code before the 1st img tag and after 2 img tag
[英]How to dynamically add em tag before img?
我想將em標簽動態地放在IMG標簽之前,圖像類為.photo。
<img class="photo" src="image.jpg" />
我想將其轉換為
<em></em><img class="photo" src="image.jpg" />
使用jQuery,我使用的是append,但將其添加到了img標簽中,
謝謝。
$("img.photo").before("<em>");
您可以使用before()方法。
您需要使用before()
jQuery("img").before("em")
編輯:好的,不需要添加結束標記。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.