Simple jQuery .size() and .length() 'not a function' error [duplicate]

Simple jQuery .size() and .length() 'not a function' error [duplicate]



This question already has an answer here:



I am getting this error:


TypeError: $(this).find('.btn-default').size is not a function. (In '$(this).find('.btn-default').size()', '$(this).find('.btn-default').size' is undefined)



As a result of this code:


console.log($(this).find('.btn-default').size());



I get the same error if I use .length() instead. I am using jQuery 3.3.1. This working example is using jQuery 3.1.1 with size(). I'm sure I'm doing something incredibly simple but wrong, but I cannot find the problem.


.length()


size()



EDIT: Once again, the problem was my bad eyesight. The answer is: length is a property, not a function.


length



Who knows why the codeply example claims to be using jQuery 3.1.1. with size() but clearly that should not be possible, according to comments below.


codeply


size()



This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.





size() is depreciated as of jQuery v1.8 and length does not accept parameters, so it would just be .length. See size() and length
– showdev
Sep 5 '18 at 20:53



size()


length


.length


size()


length





Your example is using jQuery 1.9.1, not 3.3.1 as you claim
– j08691
Sep 5 '18 at 20:54






Why exactly are you using .size() and .length()?
– Kevin B
Sep 5 '18 at 20:55





console.log($(this).find('.btn').length); fails the same way.
– CXJ
Sep 5 '18 at 20:55



console.log($(this).find('.btn').length);





In my haste to respond to all of your comments, I misread the console error messages a bit: .length did not fail, but rather a later call to .length() leftover from my experiments failed. Answer below is correct. I needed to use a property, not a function.
– CXJ
Sep 5 '18 at 21:04


.length


.length()




1 Answer
1



the size is deprected since 1.8 and removed in 3.0 see here size()



Use $(this).find('.btn-default').length (property not function ) instead


$(this).find('.btn-default').length





"property not function" is the key. I misread the docs, and then further misread my debug output on the console, and got mislead.
– CXJ
Sep 5 '18 at 21:05





@CXJ I'm glad you fixed your issue :)
– Boo Berr'ita
Sep 5 '18 at 21:07

Popular posts from this blog

Malaysia to Papua New Guinea by motorcycle?

List of Bhojpuri films

.name