Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js Convert the characters to the html

//To do this simply create a element in the DOM tree and 
//set the innerText of the element to your string. 
//Then retrieve the innerHTML of the element. 
//The browser will return an HTML encoded string.

function HtmlEncode(s)
{
  var el = document.createElement("div");
  el.innerText = el.textContent = s;
  s = el.innerHTML;
  return s;
}

console.log(HtmlEncode('&;'><"'));

//expected output: &amp;;'&gt;&lt;"
Comment

javascript covert html characters to text

const decodeHTML = s => {
    var str, temp= document.createElement('p');
    temp.innerHTML= s;
    str= temp.textContent || temp.innerText;
    temp=null;
    return str;
}

console.log(decodeHTML('&lt;'));
Comment

PREVIOUS NEXT
Code Example
Javascript :: nodejs recursively read directory 
Javascript :: react native width auto 
Javascript :: jQuert latest cdn 
Javascript :: how to convert a JavaScript iterator to array 
Javascript :: npm express-session 
Javascript :: js every x seconds 
Javascript :: get javascript min date 
Javascript :: aos js 
Javascript :: js minifier api 
Javascript :: guid generator node 
Javascript :: remove console log in production react 
Javascript :: how to get timestamp in javascript of a date object 
Javascript :: moment add 6 months 
Javascript :: auto increment schema mongoose id 
Javascript :: how do i remove all vowels from a string in javascript and return the result 
Javascript :: eof while parsing 
Javascript :: electron getPath 
Javascript :: eslint unexpected console statement 
Javascript :: express download file 
Javascript :: react router history push parameter 
Javascript :: set date input html using js 
Javascript :: how to calculate distance between two points in javascript 
Javascript :: localtunnel 
Javascript :: bootstrap modal disable close on click outside react bootstrap 
Javascript :: async await catch error 
Javascript :: jquery click hold down 
Javascript :: read csv file in javascript 
Javascript :: check if string is datestring javascript 
Javascript :: object delete with id filter javascript 
Javascript :: web-vitals react 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =