Printing emojis with JavaScript and HTML

前端 未结 2 669
情书的邮戳
情书的邮戳 2020-12-01 11:03

Why does this work:

😄

And this doesn\'t:

document.getElementById(\"emoji\").inn         


        
2条回答
  •  余生分开走
    2020-12-01 11:41

    You can also use the hacky method if you don't want to include String.fromCodePoint() in your code. It consists in creating a virtual element ...

    elem=document.createElement('p')

    ... Filling it with the Working HTML...

    elem.innerHTML = "😄"

    ... And finally getting its value

    value = elem.innerHTML

    To make it short, this works because of the fact that, as soon as you set the value of a HTML container, the value gets converted into the corresponding character.

    Hope I could help.

提交回复
热议问题