Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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;"
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #Convert #characters #html
ADD COMMENT
Topic
Name
2+7 =