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);
});
精彩评论