How to keep special characters in J-query?

This question already has an answer here:

My jquery string has special characters as follows.

$(window).load(function() {  
  var text = 'Hi there, I'm 5'5" height';
  alert (text); // out put without ' " signs
});

i want to print same as it is the out put. How to do it? In PHP it does by htmlspecialchars function. Required output is

Hi there, I'm 5'5" height

Answers 1

  • You need to escape the quotes using \

      var text = 'Hi there, I\'m 5\'5\" height';
      alert (text); // out put without ' " signs


Related Articles