Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any method to unescape '>' to '>' in JavaScript?

i want to escape some HTML in JavaScript. How can I do that?

like image 502
zjm1126 Avatar asked Apr 13 '10 04:04

zjm1126


People also ask

What can I use instead of unescape?

JavaScript unescape() The unescape() function is deprecated. Use decodeURI() or decodeURIComponent() instead.

Can I use Unescape?

unescape() Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes.

What is unescape function?

The unescape() function in JavaScript takes a string as a parameter and uses to decode that string encoded by the escape() function. The hexadecimal sequence in the string is replaced by the characters they represent when decoded via unescape(). Syntax: unescape(string)

How do you unescape in HTML?

One way to unescape HTML entities is to put our escaped text in a text area. This will unescape the text, so we can return the unescaped text afterward by getting the text from the text area. We have an htmlDecode function that takes an input string as a parameter.


1 Answers

I often use the following function to decode HTML Entities:

function htmlDecode(input){
  var e = document.createElement('div');
  e.innerHTML = input;
  return e.childNodes[0].nodeValue;
}

htmlDecode('&lt;&gt;'); // "<>"

Simple, cross-browser and works with all the HTML 4 Character Entities.

like image 181
Christian C. Salvadó Avatar answered Nov 16 '22 04:11

Christian C. Salvadó