Answers for "js encode to &"

1

js encode to &

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

encodeToAmp('&;\'><"')  //  =>  &amp;;'&gt;&lt;"
Posted by: Guest on August-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language