Search code examples
htmlpre

How to show html source code in html page


I want to display html code in html,I tried solution from SO itself, but that was not helpful or may be I'm missing something. Then, I tried following syntax, but not helpful (only getting Click Here to Apply).

<pre><code><span style='font-size:20px'>Click Here to Apply </span></code></pre>

Anyone help me to figure out, what's wrong in my approach ?


Solution

  • Tomer's answer is correct and that is the way that I would do it. But there is an alternative that uses JavaScript. You can remove the HTML of an element, and add it back as text using createTextNode(). Pass an element to this function:

    function revealElementHTML(el) {
        var html = el.innerHTML;
        el.innerHTML = "";
        el.appendChild(document.createTextNode(html));
    }
    

    jsfiddle.net/rh7RW