With jQuery and CSS, you can recover HTML and set this content as text:
$('.classe').text($('.classe').html())
And then set a CSS for the font to get the correct spacing:
.classe {
display: block;
font-family: monospace;
white-space: pre;
}
See the example on jsfiddle.
However, I advise against using this scheme as it may suffer an attack of XSS in case of displaying user content. Ideally you should make an escape from the HTML on the server side.
Update
Without Javascript, it would be possible to place HTML inside a <textarea>
or replacing HTML special characters on the server:
Examples:
<textarea>Código <strong>html</strong> aqui!</textarea>
<pre>Código <strong>html</strong> aqui!</pre>
See the jsfiddle of this example.
One way to replace characters using php is with the function htmlentities
.
Note that the textarea
is also vulnerable to Cross Site Scripting, for example if a user can write a value like the one shown below:
</textarea><script>....</script><textarea>
I don’t quite understand. Put your code there in the question.
– Jefferson Alison
I didn’t understand where JS and jQuery come in, it wouldn’t just be the case of styling via css?
– Conrad Clark
No. I want to use CSS to remove HTML formatting. For example:
<p>
same on the site, would have HTML formatting and disappear.– user2692
<font>
is a tag that has fallen into disuse, is only compatible until HTML4, but also not understood what the goal, has how to make an example in jsfiddle?– Gabriel Gartz