differences in size and length of jQuery


set of elements in the jQuery (jQuery object) as a way to get the number of elements contained in, ". size ()" function ". length" has a property.

For example, this displays the number of li elements.
<body> <ul> <li> 1 </li> <li> 2 </li> </ul> </body> HTML that you can run in both the "2" is returned.

alert( "Size: " + $("li").size() );
alert( "Size: " + $("li").length );

". Size ()" function ". Length" property of the results obtained are the same, I thought it would be better used to?
But if you simply just want to get the number of elements, ". Size ()" function call overhead minute no different from ". Length" is preferred, he says.

The .size() method is functionally equivalent to the .length property;
however, the .length property is preferred because it does not have the overhead of a function call.

( Http://Api.jquery.com/Size/ )

Tags: JavaScript


HOME > Articles of the year two thousand and eleven > jQuery differences in size and length

HOMEHOME CategoryCategory HistoryHistory

Site Search :

[HTML link code]