Utilities in jquery provides serveral utilities in the format of $(name space). These methods are helpful to complete the programming tasks.Today i am going to explain some of these methods.

$.trim()

$.trim() is used to Removes leading and trailing whitespace. Whitespace in this context is all the whitespace characters (space, tab, no-break space, etc.) and all the line terminator characters (LF, CR, etc.).

$.trim( "    lots of extra whitespace    " );

$.each()

The .each() method is designed to make DOM looping constructs concise and less error-prone. When called it iterates over the DOM elements,objects and array that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0.

$.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 );
});

$.inArray()

$.inArray() is used to Returns a value’s index in an array, or -1 if the value is not in the array.The $.inArray() method is similar to JavaScript’s native .indexOf() method in that it returns -1 when it doesn’t find a match. If the first element within the array matches value, $.inArray() returns 0.

var myArray = [ 1, 2, 3, 5 ];
 
if ( $.inArray( 4, myArray ) !== -1 ) {
   console.log( "found it!" );
}

$.extend()

$.extend() is used to Changes the properties of the first object using the properties of subsequent.When two or more object arguments are supplied to $.extend(), properties from all of the objects are added to the target object. Arguments that are null or undefined are ignored. 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()

The $.proxy method takes an existing function and returns a new one with a particular context.
This method is often used for attaching events to an element where the context is pointing back to a different object.it is used to Returns a function that will always run in the provided scope — that is, sets the meaning of this inside the passed function to 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 give the information about browsers.

jQuery.each( jQuery.browser, function( i, val ) {
   $( "<div>" + i + " : <span>" + val + "</span>" )
   .appendTo( document.body );
});

$.contains()

The contains() selector selects elements containing the specified string.
The string can be contained directly in the element as text, or in a child element.
This is mostly used together with another selector to select the elements containing the text in a group

$.contains( document.documentElement, document.body );
$.contains( document.body, document.documentElement );

$.data()

$.data() is used to give the information about data.it allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks.
We can set several distinct values for a single element and retrieve them later:

<html lang = "en">

   <head>
      <title>jQuery.data demo</title>
      <script src = "https://code.jquery.com/jquery-1.10.2.js"></script>
   </head>
	
   <body>
 
      <div>
         The values stored were <span></span>
            and <span></span>
      </div>
 
      <script>
         var div = $( "div" )[ 0 ];
			
         jQuery.data( div, "test", {
            first: 25,
            last: "tutorials"
         });
			
         $( "span:first" ).text( jQuery.data( div, "test" ).first );
         $( "span:last" ).text( jQuery.data( div, "test" ).last );
      </script>
 
   </body>
</html>

An output would be as follows
The values stored were 25 and tutorials

$.fn.extend()

$.fn.extend() is used to extends the jQuery prototype

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.fn.extend demo</title>
  <style>
  label {
    display: block;
    margin: .5em;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<label><input type="checkbox" name="foo"> Foo</label>
<label><input type="checkbox" name="bar"> Bar</label>
 
<script>
jQuery.fn.extend({
  check: function() {
    return this.each(function() {
      this.checked = true;
    });
  },
  uncheck: function() {
    return this.each(function() {
      this.checked = false;
    });
  }
});
 
// Use the newly created .check() method
$( "input[type='checkbox']" ).check();
</script>
 
</body>
</html>

It provides the output as shown below −
Untitled

$.isWindow()

$.isWindow() is used to recognise the window.This is used in a number of places in jQuery to determine if we’re operating against a browser window (such as the current window or an iframe).

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.isWindow demo</title>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
Is 'window' a window? <b></b>
 
<script>
$( "b" ).append( "" + $.isWindow( window ) );
</script>
 
</body>
</html>

It provides the output as shown below −
Untitled

$.now()

$.now() function returns a number which is representing the current time.

(new Date).getTime();

$.dequeue()

$.dequeue() is used to execute the next function in the queue

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>dequeue demo</title>
  <style>
  div {
    margin: 3px;
    width: 50px;
    position: absolute;
    height: 50px;
    left: 10px;
    top: 30px;
    background-color: yellow;
  }
  div.red {
    background-color: red;
  }
  </style>
  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
 
<button>Start</button>
<div></div>
 
<script>
$( "button" ).click(function() {
  $( "div" )
    .animate({ left:"+=200px" }, 2000 )
    .animate({ top:"0px" }, 600 )
    .queue(function() {
      $( this ).toggleClass( "red" ).dequeue();
    })
    .animate({ left:"10px", top:"30px" }, 700 );
});
</script>
 
</body>
</html>

Output of this code will be


http://codingbin.com/wp-content/uploads/2017/09/hqdefault.jpghttp://codingbin.com/wp-content/uploads/2017/09/hqdefault-150x150.jpgManoj DhimanjavascriptjQueryjquery,UtilitiesUtilities in jquery provides serveral utilities in the format of $(name space). These methods are helpful to complete the programming tasks.Today i am going to explain some of these methods. $.trim() $.trim() is used to Removes leading and trailing whitespace. Whitespace in this context is all the whitespace characters (space, tab,...coding, php, wordpress, yii, cakephp, and  jquery

Are you want to get implementation help, or modify or extend the functionality of this script? Submit paid service request