0

I am using jQuery to grab the text of a button and want to compare that text to a letter in a string. I haven't been able to get it to return true. Below is just a simplified example of what I am trying to do.

the first console log returns "a" "string" the second console log is taking an element that has the text of the letter a in it an returns "a" "string"

even though it seems they are the exact same, when I check if they are equal using a boolean it returns false.

<div class="button">
     <p>a</p>
</div>
console.log (`a`, typeof `a`)
console.log ($element.text(), typeof $element.text())
console.log('a' == $element.text());

Can anyone tell me why this is happening?

Sam Bevan
  • 11
  • 2
  • what is the type and value of $element.text() ? – anees May 02 '20 at 18:14
  • 2
    There must some spaces in the string. [`trim`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim) before comparing – adiga May 02 '20 at 18:15

0 Answers0