Fábio Luiz
Fábio Luiz

Reputation: 438

how do I compare textarea enter character

When I try to get the character from a textarea text it comes between quotes but when I evaluate him on console it appears like '↵' how to compare those values?

variable char

  1. variable evaluated on console
  2. comparison with '↵' character
  3. how it appears before evaluation

Upvotes: 1

Views: 70

Answers (1)

Rachel Gallen
Rachel Gallen

Reputation: 28583

You can execute a bit of a trick to compare the values. Check for the character and replace it with the character code if found.

See snippet example:

var vltest = document.getElementById("test1").innerHTML;

var newString = vltest.replace(/↵/g, '↵');

alert("Old: " + vltest +  " New: " + newString); //you can comment this out, just for demo purposes to show before/after

if (newString.indexOf('↵') > -1) { //check if found
  alert("Found it!")
}
<textarea id="test1">↵</textarea>

The 'downward left' arrow also has codes of &#x21B5; and &crarr; - just a piece of trivia. Feasibly you could replace the arrow with something else (other than the afore-mentioned codes), for instance a <span> tag or a non-breaking space, and then check for the index of it, but this way works..

Hope this helps

Upvotes: 1

Related Questions