I have some HTML script that I would like to make it display in a web page like the code option here:
<a href="#">test</a>
How can I do that?
Use HTML Special Character Codes var myCode = "<b>This is not bold</b>"; $('span#code-span'). text(myCode); Using text instead of html will cause tags to be rendered exposed instead of being executed.
Note: <pre> tag is used to display code snippets because it always keeps the text formatting as it.
You need to HTML-escape your text, as you can easily tell if you look at the HTML source of this very page:
<div class="post-text">
<p>I have some HTML that I would like to make it appear like the code option here</p>
<pre><code><a href="#">test</a>
</code></pre>
<p>How can I do it?</p>
</div>
You'll need to encode the angle brackets etc in order to show this on the page.
You can do this manually in html as:
<a href="#">test</a>
Where:
< = <
> = >
For other characters here's a table of character codes: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With