简体   繁体   中英

Convert decimal HTML entities to unicode characters from string

I have an extract html file from a comment system I have to use that looks like this:

<div>Plz say my name&amp;#128516;&amp;#9996;&amp;#127995;</div>
<div>Dose Amelia like donuts &amp;#127849;&amp;#127849;</div>

Obviously the part to note is all the emoji. I then pull that HTML file in using

var questionsfile = "comments.inc";
$.get(questionsfile, function(response) {
    $(".noquestions").replaceWith(response);
});

I used .replace() to convert it back to &#9996; but it now just outputs it as plain text. How do I make it so that the response output contains ✌🍩?

You need to replace its text as its html , check the demo below

 var str = `<div>Plz say my name&amp;#128516;&amp;#9996;&amp;#127995;</div> <div>Dose Amelia like donuts &amp;#127849;&amp;#127849;</div>`; var $str = $( str ); $str.find( "div" ).each( function(){ //iterate each div $(this).text( $(this).html() ); //replace text with html }) $(".noquestions").replaceWith( $str );
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="noquestions-wrapper"> <div class="noquestions"> assasd </div> </div>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM