Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 72388

Programatically change an HTML Tags Angle Bracket to `<` Text Character

$
0
0

I need to convert some HTML to text and show the HTML tags as code, in other words have a <div> show with the angle brackets and appear on screen as <div>. I know to do this I have to switch the angle brackets to &lt; and &gt;

Is there anyway of doing this programmatically with JavaScript? I've included some pseudo code below in terms of how you'd do this is if it was a string, but I need to find out how to convert the HTML tags to strings?

Codepen: https://codepen.io/emilychews/pen/KKpqoww

Any assistance would be awesome

// PSEUDO CODE

var codeHTML = document.getElementsByClassName('code-html')

for (var i = 0; i < codeHTML.length; i+=1) {

    codeHTML[i].replace('<', '&lt;')
}
<code class="code-html"><div></code>
Hi<code class="code-html"></div></code>

Viewing all articles
Browse latest Browse all 72388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>