jQuery Utililty Functions
Table of Content:
Utilities
Consider you want have a piece of text that is to be displayed to the users. But it has a lot of blank space at the beginning and end.
Instead of writing separate code for that, you can make use of jQuery's utility function $.trim()
.
-
In order to help the developers with coding jQuery offers a number of utility methods.
-
They are methods without any selectors.
Syntax: $.nameSpace
-
They help in reducing regular programming labor.
Utililty Functions
Let us see some of the commonly used utility functions
$.isArray() will return whether the given variable is an array or not.
$.isPlainObject checks is the object is created using new keyword
or not.
$.merge() combines two array elements into one.
$.each() used to iterate over arrays and objects.
Method $.noConflict()
-
This is one of the important utility method used widely.
-
Nowadays developers use more than one stack to create a page.
-
Some other stack might make use of the
$
symbol of jQuery which might result in conflict. -
To avoid such conflict, use the
$.noConflict()
utility method. -
This allows you to replace the
$
with keywordjQuery
in the script
$.noConflict(); jQuery( document ).ready(function( $ ) { // JQuery code. Here note that $ is replace by jQuery in ready function });