FastTrack
FastTrack

Reputation: 8980

jQuery Global Settings for Hides?

I have a request - not sure if it's possible.

Throughout my application, when I call the hide() method on an element, I would like it to default to hide("fade", 200) without having to type the "fade", 200 each time.

Is there a "global" setting I can set to accomplish this? Sort of like the the ajaxSetup() feature?

Upvotes: 2

Views: 57

Answers (3)

Namat
Namat

Reputation: 71

I don't believe you can create a default but you can always try to create a custom js function to handle it. You might try to create a utility js that is distributed across your site like this...

jqueryOverride = {
    hide: function(element) {
        $(element).hide("fade", 200)
    }
}

Upvotes: 0

sshet
sshet

Reputation: 1160

You need to create your custom plugin for this , call it as fadeHide or some other name , as hide is jquery function

(function($){

  $.fn.fadeHide= function(options) {

    this.hide("fade",200);

  };

});

Now you can call this plugin as

$('div').fadeHide();

Upvotes: 3

j08691
j08691

Reputation: 207901

You can create your own fade function instead, call it say myFade:

$.fn.myFade = function () {
    this.hide("fade", 200);
};
$('div').myFade();

jsFiddle example

Upvotes: 8

Related Questions