I am trying to replace a unicode character of textContent of an HTML attribute in Rails using Javascript. My present code is like this:

my_string.textContent.replace(\u25B2, \u25BC)

But this is not replacing the character. What should I change here to replace the unicode character of up-arrow to down-arrow?

2 Answers

user3742929 On

You need to put the characters into double quotes, like this:

my_string.textContent.replace("\u25B2", "\u25BC")
Jonas Wilms On

You need strings:

 .replace("\u25B2", "\u25BC")

This will however only replace the first occurence. To replace them all, use a regex:

  .replace(/\u25B2/g, "\u25BC")