Javascript: Show HTML code on a web page

The main problem in showing html code in a webpage is to write &lt; instead of < also &gt; instead of > .

A simple javascript code makes this easy.

function startReplacer(cls){
e = document.getElementsByClassName(cls);
for (var c=0; c<e.length; c++){
html = e[c].innerHTML;
e[c].innerText = html;}}

Just call this function [ startReplacer(class); ] with class name of element containing html code as parameter. If there are more than one elements with same class name then better to call the above function at end of web page like this:

startReplacer("classname"); </script>

Realated Contents:
Get source code of webpage using Javascript
Get source code across domain (any webpage) using Vbscript

No comments:

Post a Comment

Thank you for commenting. Please keep visiting.