$.fn.method()
syntax to indicate a method
call on a selection of elements. For example, when I write $.fn.addClass
, it denotes uses like $('div').addClass('blue')
or $('a.active').addClass('in-use')
. $.fn
is the prototype for jQuery element wrappers.$('div.active')
into an array of elements that you can operate on. I knew that Sizzle makes up most of the jQuery, but I was surprised to find out how huge it really is. This is the biggest feature, in terms of the number of lines, in the jQuery source code. According to my calculations, it makes up 22% of the entire code base. This overshadows the next largest thing in jQuery - $.ajax
, which takes up only 8% of library code._.filter
method, it also takes two arguments, an array of elements and a function, and returns the elements that passed the function test.load
event. Inside, jQuery passes the special flag noBubble: true
for all load
events, so that image.load events cannot pop up to the window object (which can be mistakenly perceived as window.load).jQuery.fx.interval
to your own number.$('div:gt(2)')
return all divs except the first three (indexing starts from zero). If you pass a negative number to the argument, jQuery counts back from the end of the sample.$(document).ready()
used by jQuery deferred to determine when the DOM is fully loaded.typeof
, but did you know that jQuery provides a .type()
method? The jQuery version is more reasonable than the native browser version. For example, typeof (new Number(3))
returns “object,” while $.type(new Number(3))
returns “number.” Added: As the ShirtlessKirk indicated in the comments, $ .type returns the return type of the method .valueOf ( ). So it is more correct to say that $ .type will tell you the type of the return value of the object.$('div').queue()
. This is useful if you need to know how many effects still need to be applied to the element. It is even more useful to add effects to the queue yourself. From jQuery docks: $( document.body ).click(function() { $( "div" ) .show( "slow" ) .animate({ left: "+=200" }, 2000 ) .queue(function() { $( this ).addClass( "newcolor" ).dequeue(); }) .animate({ left: "-=200" }, 500 ) .queue(function() { $( this ).removeClass( "newcolor" ).dequeue(); }) .slideUp(); });
$.fn.on
accepts an object to connect to multiple events at the same time? Example from jQuery docks: $( "div.test" ).on({ click: function() { $( this ).toggleClass( "active" ); }, mouseenter: function() { $( this ).addClass( "inside" ); }, mouseleave: function() { $( this ).removeClass( "inside" ); } });
$.active
returns the number of active XHR requests. This can be useful for limiting the number of concurrently active AJAX calls..parents()
, .next()
and .prev()
, but I did not know that there were Until versions of these methods. Essentially, these methods will select the parents / next / prev elements until they reach the transmitted stopping element.true
first argument to the clone
method.true
to the second argument. This is called “deep cloning”. The second argument is the default of the first one (which, by default, is false). Thus, if the first argument is true
and you want the second to be true
, you can omit the second argument.Source: https://habr.com/ru/post/230449/
All Articles