Andrew
Andrew

Reputation: 1873

How do I strip ‏ in Javascript?

I have an HTML element that looks like the following:

<span>&rlm;3</span>

I set up a click event handler on this element (code not shown) that gets the innerHTML of this span:

e.currentTarget.innerHTML
"‏3"
e.currentTarget.innerHTML.length
2
e.currentTarget.innerHTML.charAt(0)
"‏"
e.currentTarget.innerHTML.charAt(1)
"3"

Based on the length, it seems that Javascript/Chrome is converting the &rlm; marker to the unicode invisible character when is displayed on the console.

When the span contains no &rlm; marker, things work as expected:

e.currentTarget.innerHTML
"3"
e.currentTarget.innerHTML.length
1

Any idea on how to strip this character? I've tried .trim() and .replace().

Upvotes: 2

Views: 3616

Answers (1)

Andrew
Andrew

Reputation: 1873

e.currentTarget.innerHTML.replace(/\u200f/g, '')

Seems to do the trick.

Upvotes: 3

Related Questions