mercredi 25 novembre 2020

js conditional test for utf string of special character

Say I have a div with innerHTML set using the HTML code for a rocket: 🚀

How do I do a conditional test for that character in javascript?

E.g. how do I get below to log "rocket"

let rocket = document.getElementById("rocket")

if (rocket.innerHTML == "🚀") console.log("rocket") 
else console.log("no rocket");
<div id="rocket">
&#128640;
<div>

Aucun commentaire:

Enregistrer un commentaire