What’s the easiest way to turn an <a> into <span> keeping all the attributes and content? (except for perhaps the href).
.replaceWith() replaces the whole shebang.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can iterate an element’s attributes using the
attributesproperty. You can copy an attribute usingattribute.cloneNode(true). You can add that cloned attribute to another element’s attributes collection withelement.attributes.setNamedItem(attribute).Here’s a quick plugin that does it:
Use it like this:
Working demo: http://jsfiddle.net/gLqZJ/2
Edit: Updated above to copy event handlers and to keep the descendent nodes untouched, rather than duplicating the HTML.