jQuery - Utilities

Jquery provides several utilities in the $ (namespace) format. These methods are useful for performing programming tasks. Some of the utility methods are shown below.
$.trim()
$.trim() is used to remove leading and trailing spaces
$.trim( " lots of extra whitespace " );
$.Each()
$.each() is used to iterate over arrays and objects
$ . each ([ "foo" , "bar" , "baz" ], function ( idx , val ) { console . log ( "element " + idx + " is " + val ); }); $ . each ({ foo : "bar" , baz : "bim" }, function ( k , v ) { console . log ( k + " : " + v ); });
.each() can be called on a selection to iterate over the elements contained in the selection. .each() rather than $.each() should be used to iterate over elements in a selection.
$.InArray()
$.inArray() is used to return the index of the value in the array, or -1 if the value is not in the array.
var myArray = [ 1 , 2 , 3 , 5 ]; if ( $ . inArray ( 4 , myArray ) !== - 1 ) { console . log ( "found it!" ); }
$.extend()
$.extend() is used to change the properties of the first object using the properties of subsequent objects.
var firstObject = { foo: "bar", a: "b" }; var secondObject = { foo: "baz" }; var newObject = $.extend( firstObject, secondObject ); console.log( firstObject.foo ); console.log( newObject.foo );
$.proxy()
$.proxy() is used to return a function that will always execute in the provided scope, i.e. sets the value of that parameter inside the passed function for the second argument
var myFunction = function () { console . log ( this ); }; var myObject = { foo : "bar" }; myFunction (); // window var myProxyFunction = $ . proxy ( myFunction , myObject ); myProxyFunction ();
$.browser
$.browser is used to provide information about browsers
jquery . each ( jQuery . browser , function ( i , val ) { $ ( "<div>" + i + " : <span>" + val + "</span>" ) . appendTo ( document . body ); });
$.Contains()
$.contains() is used to return true if the DOM element provided by the second argument is a child of the DOM element provided by the first argument, whether it is a direct child or nested more deeply.
$.contains( document.documentElement, document.body ); $.contains( document.body, document.documentElement );
$.data()
$.data() is used to provide information about the data
$.fn.extend()
$.fn.extend() is used to extend the jQuery prototype
$.IsWindow()
$.isWindow() is used to recognize the window
$.Now()
Returns a number representing the current time.
(new Date).getTime()
$.IsXMLDoc()
$.isXMLDoc() checks if file is XML or not
jQuery.isXMLDoc( document ) jQuery.isXMLDoc(document.body)
$.GlobalEval()
$.globalEval() is used to execute JavaScript globally
function test() { jQuery.globalEval( "var newVar = true;" ) } test();
$.dequeue()
$.dequeue() is used to execute the next function in the queue