Skip to content Skip to sidebar Skip to footer

How To Display A Script Tag In Html And Not Execute It

I want to display a script tag that looks like:

Solution 1:

You must use a method or a tool which escapes some html characters.

For a tool please see http://www.iwantaneff.in/entifier/ for sample

So your code will be

<script>

Solution 2:

There is no native function, but you can manually create one:

function htmlEscape(str) {
    return str.replace(/</g,'&lt;').replace(/>/g,'&gt;');
}

You can manually do replace like that.

Call it like this:

htmlEscape('<script');

Post a Comment for "How To Display A Script Tag In Html And Not Execute It"