Replace an element name while retaining the attributes with jquery
Posted
by geckomist
on Stack Overflow
See other posts from Stack Overflow
or by geckomist
Published on 2010-05-21T20:06:55Z
Indexed on
2010/05/21
20:10 UTC
Read the original article
Hit count: 181
I'm trying to create a jquery setup where all instances of <i>
are changed to <em>
. It's easy enough to do with:
$("i").each(function(){
$(this).replaceWith($('<em>' + this.innerHTML + '</em>'));
});
But what I am having trouble figuring out is how to change all the <i>
tags but retain each ones individual attributes. So if I have <i style="background-color: #333;" alt="Example" title="Example">Example Text</i>
I would like it to change to <em style="background-color: #333;" alt="Example" title="Example">Example Text</em>
Thanks for any help!
© Stack Overflow or respective owner