开发者

img tag convert into div tag by using jQuery

I want to 开发者_运维百科change all img tag of a page into div tag by using jQuery. ex.

<img src="http://www.xyz.com/img.png" alt="this text i want in div" />

by using jQuery it converts into

<div>this text i want in div</div>

How we can do this by using jQuery?


You could use replaceWith

Here's a fiddle : http://jsfiddle.net/Am75c/

<img src="http://www.xyz.com/img.png" alt="this text i want in div1" />
<img src="http://www.xyz.com/img.png" alt="this text i want in div2" />
<img src="http://www.xyz.com/img.png" alt="this text i want in div3" />

$('img').each(function(){
    $div = $('<div>').html($(this).attr('alt'));
    $(this).replaceWith($div);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜