This answerThis answer provides the jQuery and normal JS methods, but this is shortest without using the DOM:
unescape(escape("It's > 20% less complicated this way.")) Escaped string: It%27s%20%3E%2020%25%20less%20complicated%20this%20way.
If the escaped spaces bother you, try:
unescape(escape("It's > 20% less complicated this way.").replace(/%20/g, " ")) Escaped string: It%27s %3E 20%25 less complicated this way.
Unfortunately, the escape() function was deprecated in JavaScript version 1.5. encodeURI() or encodeURIComponent() are alternatives, but they ignore ', so the last line of code would turn into this:
decodeURI(encodeURI("It's > 20% less complicated this way.").replace(/%20/g, " ").replace("'", '%27')) All major browsers still support the short code, and given the number of old websites, i doubt that will change soon.