1

Javascript:

var ulKopjes = document.getElementsByClassName("tabKopjes")[0].getElementsByTagName("li");
 for (j=1; j < (ulKopjes.length - 1); j++){
  debugger;
   if (ulKopjes[j].hasClass('activeTab')){
    debugger;
   }
 }

Is there an obvious reason that I get the error 'Uncaught TypeError: undefined is not a function'?
I checked the values in the array, those ar 'li' items, that's correct.

SeinopSys
  • 8,787
  • 10
  • 62
  • 110
Grafit
  • 681
  • 11
  • 36

2 Answers2

1

try

$('.tabKopjes').eq(0).find('li').each(function() {
   if ($(this).hasClass('activeTab')) {
       //do stuff
   }
});

or if the li are direct children of .tabKopjes use .children instead of .find

If you are just after the li with the class active tab you can do

$('.tabKopjes').eq(0).find('li.activeTab')
Pete
  • 57,112
  • 28
  • 117
  • 166
  • @OP This is the way it should be written using jQuery, utilize it if it's already there. – SeinopSys Dec 09 '14 at 10:08
  • You're welcome! `eq(0)` is the first item in the found list like your `[0]` on the array. http://api.jquery.com/eq/ – Pete Dec 09 '14 at 10:23
0

hasClass is not a pure-native-JS method and it does not exist. It's a jQuery function, so you have to use jQuery to get your elements, for example:

var ulKopjes = $('.tabKopjes:first > li');

If you do not use jQuery, you have to use another way to check for a given class: Test if an element contains a class?

Community
  • 1
  • 1
Liglo App
  • 3,719
  • 4
  • 30
  • 54