0

This is probably a basic, nooby question but I have a JS function which toggles specific text (in this case Unicode, both characters are capable of being displayed). JS Fiddle here.

HTML Here:

<div class="header" style="cursor: pointer;"> <span class="arrowTog">&#9654;&nbsp;</span>
<b>Merchant</b>

JS Here:

$('.header').on('click', function () {
var arrow = $(this).find('.arrowTog');
if (arrow.text().contains('▼')) {
    arrow.text('▶');
} else {
    arrow.text('▼');
}

});

This works properly in Firefox, with the "arrow" toggling to the down position. However, this does not occur on Chrome. I just get an error that says: "Uncaught TypeError: arrow.text(...).contains is not a function".

Does anyone have any idea of what could be causing this error, and what can I do to enable it to work properly across browsers? Thanks

WhyEnBe
  • 295
  • 7
  • 22
  • You should include the HTML in this post as I believe the difference between writing the unicode or the actual character could be the cause of the problem. EDIT: oh, yeah, it must be the string.contains function. Whatever. – Domino Jun 15 '15 at 18:06
  • As shown in the linked question, you should test your `indexOf` result for a match (or in your case, a non-match) of `-1`. `indexOf` and `contains` are different functions that do different things; it is not a drop-in replacement (but it almost is). – apsillers Jun 15 '15 at 18:18
  • Thanks for the assistance – WhyEnBe Jun 15 '15 at 18:22

0 Answers0