-3

I have string such a:

"<p>Some text <em>Italic string</em> ... </p><em>Second str</em>"

How can I replace all em tags to i tags ?

In result I need:

    "<p>Some text <i>Italic string</i> ... </p><i>Second str</i>"
3
  • 3
    What have you tried? This is ridiculously simple, so you need to show us what you've tried and what didn't work. Commented Sep 13, 2017 at 14:59
  • I tried it:function replace_em_to_i(content) { var c = content; c =c.replace(/<em>/g,"<i>"); c =c.replace(/<\/em>/g,"</i>"); return c; } But I am not sure that it is the best solution Commented Sep 13, 2017 at 15:02
  • you would try it may help you var value = $("#abc").val(); value = value.replace(/\em/g, 'i'); Commented Sep 13, 2017 at 15:06

1 Answer 1

0

var replaceTag = "<p>Some text <em>Italic string</em> ... </p><em>Second str</em>";
replaceTag = replaceTag.replace(/<em>/g, "<i>");
replaceTag = replaceTag.replace(/<\/em>/g, "</i>");
console.log(replaceTag);

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.