1

How to replace <ins> tag with <del> tag and keep attributes of it in javascript or jquery? like the following

<ins data-author="auth1" data-ins-username="user1">auth1 text</ins>
<!-- After -->
<del data-author="auth1" data-ins-username="user1">auth1 text</del>

I found similar question with answer but it doesn't keep attributes.

4

1 Answer 1

5

You can use jquery .replaceWith() to replacing a tag with another. In function get outerHTML of element and replace tag name with another.

$("ins").replaceWith(function(){
    return this.outerHTML.replace("<ins", "<del").replace("</ins", "</del")
});

$("ins").replaceWith(function(){
    return this.outerHTML.replace("<ins", "<del").replace("</ins", "</del")
});
console.log($("del")[0].outerHTML);
del { color: red }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ins data-author="auth1" data-ins-username="user1">auth1 text</ins>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.