Unescape HTML entities in Javascript?

前端 未结 30 2993
野趣味
野趣味 2020-11-21 05:40

I have some Javascript code that communicates with an XML-RPC backend. The XML-RPC returns strings of the form:


30条回答
  •  终归单人心
    2020-11-21 06:03

    In case you're looking for it, like me - meanwhile there's a nice and safe JQuery method.

    https://api.jquery.com/jquery.parsehtml/

    You can f.ex. type this in your console:

    var x = "test &";
    > undefined
    $.parseHTML(x)[0].textContent
    > "test &"
    

    So $.parseHTML(x) returns an array, and if you have HTML markup within your text, the array.length will be greater than 1.

提交回复
热议问题