While working with the New York Times article API I discovered that they return encoded article leads. This fixed that right up.
var decoded = $('<textarea/>').html(encoded).val(); |
While working with the New York Times article API I discovered that they return encoded article leads. This fixed that right up.
var decoded = $('<textarea/>').html(encoded).val(); |
Perfect.
Great!
Similar to PHP htmlentitydecode, but easier…
So easy can be the life of a JS coder with jQuery
thanks you,
it is much helpful for me
Great :p
Great! Thanks so much! ^^
Anyone know if this still works? Doesn’t seem to be for me.
Yes. Try this:
var encoded = “" ' & < >”;
alert(encoded);
var decoded = $(‘<textarea />’).html(encoded).val();
alert(decoded);
Gabriel:
Only works for . But…
For first create (instead of the textarea)
Then code $(‘myinput’).val( $(‘#tmp’).html());
It will put the decoded text into the element’s value property.
This is because JQs “html()” function uses the the DOMs “innerHTML” property, then decodes that text. doesn’t have an innerHTML prop.
What if I need it the other way around?