I am trying to apply an effect to the first element in an array but I recieve this error:
$(...)[0].hide is not a function
Here is my code:
var contain = $('.commentFormContainer');
(contain.length >= 2 ) ? contain[0].hide();
I am trying to apply an effect to the first element in an array but I recieve this error:
$(...)[0].hide is not a function
Here is my code:
var contain = $('.commentFormContainer');
(contain.length >= 2 ) ? contain[0].hide();
You need to use eq() to get the jQuery object. You can not use indexer as it will give you DOM object and you can not call hide on it.
contain.eq(0).hide();
Or you can use :eq in selector.
$('.commentFormContainer:eq(0)').hide();
Note that since JavaScript arrays use 0-based indexing, these selectors reflect that fact. This is why $('.myclass:eq(1)') selects the second element in the document with the class myclass, rather than the first. In contrast, :nth-child(n) uses 1-based indexing to conform to the CSS specification, Reference.