Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8002673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:26:00+00:00 2026-06-04T16:26:00+00:00

I am tryign to override the JQuery’s .show and .hide methods to launch trigger

  • 0

I am tryign to override the JQuery’s .show and .hide methods to launch trigger events before and after they are called with the following code.

$(document).ready(function () {
    $('#dataBox').bind('afterShow', function () {
        alert('afterShow');
    });
    $('#dataBox').bind('afterHide', function () {
        alert('afterHide');
    });
    $('#dataBox').bind('beforeShow', function () {
        alert('beforeShow');
    });
    $('#dataBox').bind('beforeHide', function () {
        alert('beforeHide');
    });
    $('#toggleButton').click(function(){
        if($('#dataBox').is(':visible')) {
            $('#dataBox').hide ();
        } else {
            $('#dataBox').show();
        }
    });
});

jQuery(function ($) {
    var _oldShow = $.fn.show;
    //Override jquery's 'show()' method to include two triggered events before and after
    $.fn.show = function (speed, oldCallback) {
        return $(this).each(function () {
            var obj = $(this),
                newCallback = function () {
                    if ($.isFunction(oldCallback)) {
                        oldCallback.apply(obj);
                }
                obj.trigger('afterShow');
            };
        obj.trigger('beforeShow');
            _oldShow.apply(obj, [speed, newCallback]);
        });
    }
});

jQuery(function ($) {
    var _oldHide = $.fn.hide;
    //Override jquery's 'hide()' method to include two triggered events before and after
    $.fn.hide = function (speed, oldCallback) {
        return $(this).each(function () {
            var obj = $(this),
                newCallback = function () {
                    if ($.isFunction(oldCallback)) {
                        oldCallback.apply(obj);
                }
                obj.trigger('afterHide');
            };
        obj.trigger('beforeHide');
            _oldHide.apply(obj, [speed, newCallback]);
        });
    }
});

I have the following Markup:

<input type='text' id='dataBox'/>
<input type='button' value='toggle' id='toggleButton' />

When I click the toggle button the ‘beforeHide’ and ‘beforeShow’ events are triggering while the ‘afterShow’ and ‘afterHide’ aren’t. Can anyone clue me in as to what I am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T16:26:01+00:00Added an answer on June 4, 2026 at 4:26 pm

    plz check the demo fiddle . hope it works

    $.show / $.hide – override function:

    (function($){
    $.override ={'show': $.fn.show, 'hide': $.fn.hide};
    
    $.each($.override,function(M,F){
    
            var m=M.replace( /^\w/, function(r){ return r.toUpperCase(); });
    
            $.fn[M] = function(speed, easing, callback) {
    
                var args=[speed||0,easing||'',callback||function(){}];
    
                if( $.isFunction(speed)){
                    args[2]=speed;
                    args[0]=0;
                }                   
                else if( $.isFunction(easing)){
                    args[2]=easing;
                    args[1]='';
                }                   
    
                if(!this.selector){
                    F.apply(this, arguments);
                    return this;
                }
    
                return this.each(function () {
                    var obj = $(this),
                        oldCallback = args[args.length-1],
                        newCallback = function () {
                            if ($.isFunction(oldCallback)){
                                oldCallback.apply(obj);
                            }
                            obj.trigger('after'+m);
                    };
    
                    obj.trigger('before'+m);
                    args[args.length-1]=newCallback;
    
                    //alert(args);
                    F.apply(obj,args);
    
                });
            }
    });
    })(jQuery);
    

    usage

    jQuery(function($){
    var $dataBox=$('#dataBox').bind('beforeHide afterHide beforeShow afterShow', function(e) {
        alert(e.type);
    });
    
    $('#toggleButton').bind('click',function(){
        $dataBox[$dataBox.is(':visible')?'hide':'show'](100,'swing',function(){ alert('end of animation');});
        return false;
    });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a jQuery plugin and can't seem to override the default settings,
I am trying to override the getJSON function in jQuery to provide additional params
I'm trying to override the standard styling of a listview li element in jquery
I have a flash object that I am trying to show and hide along
I am trying to override the jQuery ajax function to handle a default action
Mornin' all, I have troubles to play with jQuery UI autocomplete widget events. I
I'm trying to override a class derived from Activity (called NativeActivity) so I can
I am trying to use jquery to override the default tabbing navigation. I cannot
I'm trying to override the default jquery text for client validation in an MVC
Trying to override a tostring in one of my classes. return string.Format(@ name =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.