Search code examples
javascripthtmlhtmlspecialchars

html special symbols is displayed as characters


I've been trying to set content of a text input dynamically using JS, the problem I encountered is I can not have the browser render the special symbols rather than chars so for example

document.getElementById("textField").value = "nbsp";

Instead of displaying a space it displays &nbsp, anybody got any idea?

Thanks a lot


Solution

  • What about using jquery and this:

    $("#textField").html('&nbsp').text()
    

    Or in more general:

    $(element).html(encodedString).text()