0

I have this line of code (where 'e' is a click event):

var type = $(e.currentTarget.parentNode)[0].classList[0];

which is producing this error in IE7 (using Companion.JS to report errors):

'0.classList.0' is null or not an object

I tried the following variations on my code, but get the same result:

var type = $(e.currentTarget).parent()[0].classList[0];
var type = $(e.currentTarget).parent()['0'].classList['0'];

This code works in the latest Chrome and Firefox browsers. Any idea what's going on here?

Jeff
  • 1,051
  • 1
  • 13
  • 26

1 Answers1

1

First check the .length of $(e.currentTarget.parentNode), you might have to add a condition for IE because the currentTarget is inconsistent with other browsers.

Also, classList is not supported in IE.

Code with classList does not work in IE?

parse the .attr('class') or [0].className

Community
  • 1
  • 1
meder omuraliev
  • 183,342
  • 71
  • 393
  • 434