escape in javascript

function escapeHtml(str) {
    return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#039;");
}

4
3
Mushroom Man 110 points

                                    function escapeHTML(text) {  
    var replacements= {&quot;&lt;&quot;: &quot;&amp;lt;&quot;, &quot;&gt;&quot;: &quot;&amp;gt;&quot;,&quot;&amp;&quot;: &quot;&amp;amp;&quot;, &quot;&quot;&quot;: &quot;&amp;quot;&quot;};                      
    return text.replace(/[&lt;&gt;&amp;&quot;]/g, function(character) {  
        return replacements[character];  
    }); 
}

4 (3 Votes)
0
0
1
Qirequiam 95 points

                                    &quot;\\n&quot;;

0
0
4
7

                                    escape sequences in javascript
\' single quote
\&quot; doucle quote
\\ backslash
\n newline
\r carriage return
\t tab
\b backspace
\f form feed

4 (8 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
js text escape html attribute escape in javascript escape * js how to escape ' in js js escape html tag javascript escape html text escape character javascript for * escape string for html htm js escape javascrip escape() escape ` javascript meaning of escape in javascript js string / escape escape strings javascript javascript escape newline in string escape string js character escape js escape character function js escape symbols javascript what is use of escape in js how to escape javascript opretor js escape to html use n escape character in javascript javascript &quot;.escape(&quot; js htzml escape escape to new line javascript escape html special characters javascript escape html in javascript string escape character for &lt; in javascript print escape characters in javascript how to auto escape html tags in javascript hwot o escape // in js new line escape sequence in javascript escape strings js escape strings in javascript javascript string escape &quot; how to escape &quot; in js escape code js escape meaning in javascript escape a string javascript how to use escape sequence in javascript escape sequence example in javascript escape * in javascript javascript how to escape string html special characters escape js escape string javascript html escape string javascript htm javascript escape - js how to escape new lines escape new lines js escape keyword in javascript how to escape value in javascript how to escape an opperatorin javascript how to escape an operation in javascript escape html from string escape ' javascript escape string to next line javascript &amp; escape character javascript escape escape character javascript escape sequence in javascript + \\ new line escape sequence js escape string html javascript escape string for html attribute javascript escape ` function w3 js escape all escape characters in javascript escape html from a string javascript replace characters with html escape escape character in javascript in javascriptinfo escape sequence in javascript string escape ed in javascript escape html using javascript escape \n \r string javascript escape js function escape javascript var js string escape / how to escape a ' javascript escape html to string javascript js how to do something on escape use of escape in javascript escape html javascript meaning javascript escape hypehn in string javascript escape - in string escape keyword on js javascript string \t escape javascripot escape characters js escape ` js enter escape character \n in string javascript escape function escape &quot; javascript use escape characters in a string javascript js escape ! character escape javascript escape \ js javascript html escape string escape characters in JS string JS escape HTMLEntities how do you escape a . in javascript how to use escape characters in js js escape . how to use escape in javascript html escape javascript escape character escape character in js html escape jjs w3schools javascript escape string example for escape sequence in javascript javascript escape string for html use of escape character in javascript escape strings in javascip javascript escape ' characters js &amp; escape escape html tags in javascript the javascript escape character string escape rules js how to escape html elements in string in javascript escape fun in js how to use escape character in javascript javascript script escape html entities js escape script tag escape ' string Javsscript escape string Javsscript escape &quot; js what is an escape character js what characters are not escape in javascript java script string escape how to escape html for javascript escape character on javascript jquery escape string string html escape how to identify escape characters in javascript escape html code javascript escape htmo charter in jquert javascript html entities escape javascript to escape html special characters escape html string javascript escape function in javascript what is escape character in javascript jquery.html escape how to escape new line character in javascript js escape() js html escape characters html escape for { escape character innjavascript escape() javascript escape a new line js escape character for &amp; in js escape for javascript string escape characters js escape tags in jquery escape + in js string escape + in js escape characters in javascript objects string escape html escape character &amp; javascript how to escape &lt;/script javascript escape() js escape() js~ escape character for javascript do i have to use escape characters in javascript escape string in js escape string in html javascript escape single quote js string escaper js use unescaped string escape operator in javascript javascript escape sequence new line escape html escape @ html js how to escape all html in a string what is escape in javascript escape character from javascript escape html string javascript html escape \n html to string escape javacript escape value escape javascript object what does escape js do escape newline javascript escape newline js how to escape javascript funciton javascript html escape function javascript u escape javascrtip escape html script in html escape javascript escape codes escape statements in js how to escape strings in javascript &quot;&amp;#039;&quot; escape js the javascript escape character is the / javascript what is escape formatjs escape html tag javscript escape string escape &lt; in javascript hot to escape . in javascript escape characters js escape ? js string escape a \ in js escape html attribute in javascript escape js ' javascript value = script tag escape characters js keyword escape escape new line javascript escaping new line in javascript html escape characters jquery html escape characters javascript js escape ? escape - in js html escape string js &quot; escape javascript encode html escape html jquery escape in string javascript escape \&quot; javascript string javascript \ escape escape js in js escape characters string javascript escape sequence for in javascript jquery html encode text escape chars javascript escape() html best way to pass special characters escape js &lt;%=%&gt; jquery escape html string using escape characters in javascript how to add escape character in string in javascript escape characters in string javascript escape \ in javascript escape js variable characters javascript escape html special characters javascript string escape characters how to print \n in javascript how to escape &quot; in html javascript escape tag sign in js escape parameters in javascript function \ need for escape letter in javascript text escape sequence javascript escape : in js js escape \ marked js escape html javascript escappe t jquery convert html %lt use escape character in javascript javsascript escape char for backslash scape text javascript $ scape text javascript javascrtip escape jquery encoding to html jquery escape function auto escape javascript string escape a string in javascript how to escape \ in javascript how to generalize escape string into html format in javascript js escape sequence javascript handle escape sequence in function javascript escape browser support nodejs html encode ingnore &lt;&gt;&quot; javascript encoding special characters escape sequesnce in js how to escape for and in in javascript escape characters in javascript\ javascript special escape sequence escape in javascript escape sequence js escape &quot;/&quot; in javascript option text not converting &amp;lt javascript backslash sign javascript escape html entities javasript escape &amp;#39; function to escape charachters in jquery escape \ javascript javascript escape enter escaping a / javascript escape character in javascript javascript javascript escaper escape notation javascript js backslash n escaping strings in javascript js convert query special characters javascript unescaped line break character escape sequences javascript js encode html convert special characters to html in javascript javascript from scaped string to normal string escape html elements javascript escape sequence code javascript escaping html in javascript javascript escape tags escape string js javascript escape \ js keep escape characters js include escape characters js show escape characters javascript scape a variable js backslash as string special characters breaking text js js escape function escape \n javascript javascript escape \n javascript add escape characters add escape characters to string js string escaper js escape and should in javascript encode special characters in javascript special characters javascript string escape characters javascript html escape function javascript js escape &lt; escape special characters in javascript js string escape &quot; &quot; escaping characters js escape caracters javascript escaping characters in javascript new line in javascript string escape &quot;&quot; in js escape sequence in js Use escape characters to alert escape charecters in string js escape text javascript escape html characters in javascript escaping js \ escaping js js special signs new line in javascript javascript escap string javascript escape new line character escape javascript string escape javasprict escaping javascript escapehtml javascript escaping in javascript strings js escape from html/js to string escape character in string to js object js escape text javascript escape sequences javascript / escape new line javascript escapte characters javascript escape ' in js javascript special characters escape javascript unexcape character codes javascript escape() javascript + escape sequence escape html function Convert special characters to js javascript have special characters javascript function to escape special characters javascript function to escape html characters html escape special characters javascript javascrtip HTML escaping escape character function javascript javascript escaped text jquery HTML Entity Encode escape special character javascript javscript escape escape js &quot; js excape &amp;quot; js escape ' js escape html special characters javascript escape / js escape new line how to excape pramiters with js escape characters in javascript \\n javascript escape a string escape symbol javascript string to escape javascript js escape ( in string how to escape characters in javascript how to escape &quot; in javascipr escape char in javascript string with special characters javascript escape js chars how to escape this sign / in javascript how to escape / in javascript how to escap character in javascript encode html entities jquery escape character javascript escape sequence in javascript javascript escape code into string htmlsafe jquery character escape sequence javascript escape carector for \ in javscript jquery sanitize string javascript escape characters in string javascript next line javascript escape to html escape jquery javascript escape character esc html js how not to get a string in jquery n! in js special characters string javascript javascript special characters java script escape sequences escaping special characters in javascript javascript escape cahracter how to escape a string in javascript js escape ; new line in string javascript escapeHtml().replace javascript how to escape a string escape ' in javascript javascript string escape special characters js escape / js escape character js escape special characters jquery html escape how to log escape characters in order javascript javascript escape all html characters escaping in javascript escape html tags javascript dec str.escapeHTML is not a function escaping cxharacters in Javasscrjpty javascript string escaping how to escape // in http javascript how to escape // in javascript escape() in javascript string escape js escape parameters javascript escpaed js how to escape . in javascript escape characters in js escape character in javascript for + escape character in javascript how to excape &quot; in string javascript what are escape characters in javascript escape characters javascript how to escape special characters in js string format jaavscirpt escape ${} skip CHARACTER in javascript how to use escape in js javascript encode enter escape piece of text js escape &lt;&gt; in javascript escape &amp; in javascript escape ' JS escape value javascript how to cancel special charactera js javascript escape line break javascript escape html brackets escape special charecters js \f in javascript escape escape html from text on jquery jquery un html escape how to escape all characters in javascript js html escape javascript how to escape \ javascript what do i need to escape js store \n as tring escaper escapeHtml js html javascript escape html javascript escaped escape character js jquery encode html js special characters in string how to escape a character in javascript js escaping characters js escape $ escape method js js escape newline jquery html escape code jquery html escape html javascript string special characters jquery escape html code javascript enter symbol in javascript escape string to html javascript string escape a character javascript escape &lt; javascript escape string &lt; javascript propery add escape charcters to a string js add esca[pe charaters to a string characters in javascript javscript escape &quot; format string with escape characters javascript how to escape ' in javascript add escape characters to string javascript escape sequences in javascript escape [ in javascript escape / in javascript escape &lt;&gt; javascript js escape break javascript characters to escape javascript escape special characters in string scape the line js ESCAPE CHAR IN JS escape html characters javascript javascript print string with escape characters javascript escape ' html escape characters js javascript escape backslash javascript string escaped escapehtml javascrip javascript escape characyers javascript escaping characters escape html js html escape string js js escape characters escape &quot; in js javascript Character escaping how to escape &quot; and ' in javascript input html escape javascript how to escape string in javascript Javascript escape &lt;&gt; put escape character in string javascript special characters in javascript jquery escape html javascript escape text for html \' js escape sequence javascript string escape javascript jquery sanitize html jsescape javascript escape string us slash in javascript string escape ' on js file escape special characters javascript javascript escape \ in string how to string javascript lines js escape strings javascript Escape Sequence escape new line in quote javascript how to escape \ javascript escape - javascript creating string with brakes in javascript escape chararcter in js string escaping in javascript string having n need to be enter javascript javascript string escape escape string in javascript escape ? javascript insert a new line using concat function javascript add enter into quotes js what ar eescape characters in javascript escape @ in javascript js escape string escape characters in javascript escape html javascropt javascript escape js special characters html escape js escape js string escaping character in javascript javascript escape html string jquery encode html entities js &amp;lt;div&amp;gt; to &lt;div&gt; javascript function escape escape () in javascript how to add escape character to string in javascript escape javascript + js new line escape escape \in js escape \n js escape javascript in html file what characters to escape for javascript strings javascript escape html characters javascript add escape characters to string escape html in js escapehtml js js how to escape &amp;code html special characters jquery js escape print string with \n js jquery html encode javascript escape {} how to escape in javascript _.escape jquery javascript escape ` escape html in javascript escape special characters javascript js html string escape variable escape method not working in node js javascript escape special characters js all characters to escape convert div into escape string jquery html encoding js escapable characters how to escape special characters in javascript string html escape javascript espcae html chars javascript javascript scape string escape &quot; javscript crlf javascript string what is escape javascript escape js javascript escape characters escape in js escape ( javascript how to escape your strings in javascript escape javascript &amp;quote; js javascript string backslash escape mysql string javascript php escape string character jquery escape string quotes escape string javascript c# json string escape online new line escape character javascript jquery escape javascript encode line break js escape html javascript escape html escape &quot; in jquery escape html javascript how to escape line break in javascript how to escape n in javascript escape characters javascript new line how to escape html in javascript javascript html escape escape javascript and display as text in html escape html javascript and display as text javascript escape newline
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source