2

I need to show "<>" symbols for my string "DummyText". When i run and inspect the element, it converted to be DOM element in HTML like . This is the code I am trying to do

<p><a href='' title='Survey Link'><DummyText></a></p>

4 Answers 4

6

Use &lt; and &gt; instead, from here

<p><a href='' title='Survey Link'>&lt;DummyText&gt;</a></p>

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

Comments

1

For HTML you have to encode special characters:

<p><a href='' title='Survey Link'>&lt;DummyText&gt;</a></p>

Comments

1

Use &lt; to display < and &gt; to display > in HTML

document.getElementById('anc').innerHTML="&lt;Dummy Text&gt;";
<p><a id="anc" href='' title='Survey Link'></a></p>

Comments

1

What's happening is that the reserved characters <> are being parsed as HTML. Since <Dummy Text> doesn't exist as a tag, it swallows it so that it doesn't appear on your page.

To fix this you need to use HTML character codes. Instead of inserting the symbol < use the string &lt; and instead of > use &gt;

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.