YouTip LogoYouTip

Misc Jquery Sub

.example {background-color:#f3f3f3; padding:10px; border:1px dashed #ccc; margin-bottom:10px;} .example pre {margin:0;} .note {color:#999; font-size:12px;} .tryitbtn {background-color:#4CAF50; color:white; padding:10px 20px; text-decoration:none; border-radius:5px; display:inline-block; margin-top:10px;} .tryitbtn:hover {background-color:#45a049;}

jQuery jQuery.sub() Method

jQuery Miscellaneous Methods

Example

Add a method to jQuery sub so that it is not exposed externally.

(function(){
    var sub = jQuery.sub();
    sub.fn.myCustomMethod = function(){
        return 'just for me';
    };
    sub(document).ready(function(){
        alert(sub('body').myCustomMethod());
    });
    alert(typeof jQuery('body').myCustomMethod); //undefined
})();

Try it yourself Β»


Definition and Usage

The $.sub() function creates a new copy of jQuery whose properties and methods can be modified without affecting the original jQuery object.

Note:

  1. Deprecated since jQuery 1.7, and will be moved to a plugin in jQuery 1.8.
  2. $.sub() does not attempt any form of isolation. All methods in the jQuery copies still point to the original jQuery. (For example, event binding and triggering still happen through the original jQuery, data is bound to elements through the original jQuery, Ajax requests and events are run through the original jQuery, etc.)

Syntax

Note: This method does not accept any arguments.

_$_.sub()

More Examples

Override some jQuery methods

Override some jQuery methods to provide new functionality.

Create a plugin

Create a plugin that returns specific methods of the plugin.


← Misc Jquery ReadyexceptionMisc Deferred Resolvewith β†’