question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

e.target.className.indexOf is undefined if target is svg element

See original GitHub issue

I needed to change line #L447 (https://github.com/isteven/angular-multi-select/blob/master/angular-multi-select.js#L447) because clicking on a svg element was not working as expected.

if ( e.target.className.indexOf === undefined || e.target.className.indexOf( 'multiSelect' ) === -1 ) {

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

8reactions
ztischenkosilobreakercommented, Dec 8, 2017

I had the same issue with ‘use’ tags that we use inside ‘svg’ tags. To fix this error you can extend SVGAnimatedString prototype (as this is a type that className property returns in this case - apparently it does not have indexOf method, hence the unhandled exception), like this:

(SVGAnimatedString.prototype as any).indexOf = (() => {
    return function() {
        return this.baseVal.indexOf.apply(this.baseVal, arguments);
    };
})();

Once you drop this inside root directory of your app, the issue will be resolved as now your ‘use’ tags (or any other tag that returns type SVGAnimatedString type, rather then string, for className property of the node element) will have indexOf method.

In my case adding ‘notranslate’ to each svg was not best solution as on the page there was a lot of svgs added at different times by different components.

Hope it will help someone out there as well.

0reactions
mattferrincommented, Aug 22, 2015

@sandun86 Thanks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get indexOf proper className of targeted element?
I have an target element which is a SVG which has two properties baseVal and aniVal , So I'm trying to get the...
Read more >
TypeError: el.className.indexOf is not a function
I have link inside svg element. When i click on this element i have error “TypeError: el.className.indexOf is not a function” (o forms.js:23) ......
Read more >
a[b].target.className.indexOf is not a function, at least not mine
I take a look in our TrackJS console and I see that the PayPal checkout integration button is throwing an error that it...
Read more >
Element.className - Web APIs | MDN
The className property of the Element interface gets and sets the value of the class attribute of the specified element.
Read more >
target Event Property - W3Schools
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found