Search code examples
javascriptjqueryhtml-encode

How do I convert an HTML Entity Number into a character using plain JavaScript or jQuery?


I'm looking for a way to convert HTML entity numbers into a character using plain JavaScript or jQuery.

For example, I have a string that looks like this (Thank you, jQuery! Punk.)

Range1-of-5

And what I need is:

Range1-of-5

I've found String.fromCharCode() where I can get the character with just the decimal value, but I'd like to see if anyone else has a solution before I possibly reinvent the wheel. :)


Solution

  • $("<div/>").html("Range1&#45;of-5").text()
    

    http://jsfiddle.net/durilai/tkwEh/