it's simple html tag related problem, I guess.
I want to share few lines of code in my blog, and I want to write <h1> heading</h1>
. visitors must see <h1> heading </h1>
, and not just heading. do I need to use JavaScript for this, please help me with this problem.
CodePudding user response:
you can use HTML Entities like < , >
<h1><h1>heading;/h1></h1>
and this link may help you https://www.w3schools.com/html/html_entities.asp
CodePudding user response:
There are two ways of doing this:
- Escape the Characters using HTML Entities or Using a JS Library
- Dynamically add the content using JavaScript
textContent
Property.
Here is a Sample code using both:
const codeSnippet = document.getElementById("codeSnippet");
codeSnippet.textContent = "<h1>Heading</h1>";
<div>
<p>Escaping:</p>
<code>
<h1>Heading</h1>
</code>
</div>
<div>
<p>Dynamically added usisng JS:</p>
<code id="codeSnippet"></code>
</div>