running into a weird thing and I'm not sure what's going on.
I've grabbed the index of a DOM element via .index()
, found a matching element via .get()
and I'm trying to add a class to it via .addClass()
.
My console is returning the error: "Uncaught TypeError: Object #<HTMLLIElement> has no method 'addClass'
"... which is especially odd because my Log shows the HTML element just fine (http://cloud.dhut.ch/image/2W3S0R3k2h2U)
Am I missing something? It's not returning in an array or anything. Confused.
Thanks!
JavaScript:
nFLi.get(active).addClass('active')
;
jQuery addClass() Method jQuery HTML/CSS Methods. Example. ... The addClass() method adds one or more class names to the selected elements. This method does not remove existing class attributes, it only adds one or more class names to the class attribute. Tip: To add more than one class, separate the class names with spaces.
The addClass () method is an inbuilt method in jQuery UI framework which is used to manage user interface visual effects. This method adds class to all selected elements along with animating all the defined styles in CSS properties.
The add () method adds elements to an existing group of elements. This method adds elements on the whole document, or just inside context elements if the context parameter is specified. Required. Specifies a selector expression, a jQuery object, one or more elements or an HTML snippet to be added to an existing group of elements
jQuery – create object oriented classes in jQuery Published by Joe Buckleon September 23, 2015 Create an object oriented style with jQuery. Make use of the constructor() method and access public and private methods from within the class scope.
You need to wrap it into a jquery object.
$(nFLi.get(active)).addClass('active');
Or you could use .eq method instead of .get
, which returns a jquery object instead of original HTMLElement.
nFLi.eq(active).addClass('active');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With