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 862189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:06:04+00:00 2026-05-15T09:06:04+00:00

Short version of question: see title Long version of question: I’ve used jquery’s show()

  • 0

Short version of question: see title

Long version of question:
I’ve used jquery’s show() and hide() functions extensively in my code and just encountered a bit of a problem: they work by changing the display attribute of the element to ‘block’ or ‘none’ respectively, so that if you have somethin that has display: inline and then hide and show it, you’ve changed its display to block, which screws up the layout in a couple of cases.

In my code, whenever i want something to be hidden initially i give it a class ‘hidden’. This class is simply {display: none}. I’d like the change show and hide to remove or add this class, instead of directly changing the display attribute, so that if you add the hidden class and then remove it again (ie hide and show something) then it’s back to exactly how it was to start off with (since adding a class overrides the attributes rather than directly changing them). Something like this (this is a little pseucodey as i don’t know how to set the function up properly – let’s assume that ‘this’ is the object that show/hide was called on)

function show(){
  this.removeClass("hidden");
} 

function hide(){
  this.addClass("hidden");
} 

how and where would i go about overriding the jquery methods? (I’m not a javascript expert)

thanks – max

  • 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-05-15T09:06:05+00:00Added an answer on May 15, 2026 at 9:06 am

    I wouldn’t override jQuery’s methods when you could create your own. Overriding would very likely cause unexpected behavior in plugins.

    jQuery already has a method called toggleClass() that would seem to fit what you’re looking for.

    $someElement.toggleClass('hidden');
    

    Docs: http://api.jquery.com/toggleClass/


    EDIT:

    But to answer your specific question, to override a jQuery method, you would do something like this:

    jQuery.fn.show = function() {
        // Your custom code
    }
    

    Or to create a custom method:

    jQuery.fn.customMethod = function() {
        // Your custom code
    }
    

    Before doing so, it would be a good idea to consult this document:

    http://docs.jquery.com/Plugins/Authoring

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Short version question : Is there navigator.mozIsLocallyAvailable equivalent function that works on all browsers,
SHORT VERSION OF QUESTION: So basically my question is: How can I set the
The short version of the question - why can't I do this? I'm restricted
The short version of the question: I do: x = y . Then I
I have a short version of the question: I start a thread like that:
This is basically a rails 3 version of this question . Short of parsing
Short version: Can I grant access to external databases to a role? Long version:
Short version of the question: Since I already have TortoiseHg, I right clicked on
The short version of my question is: How do I access the phone numbers
Note: This question refers to a very old version of jQuery.validate() (version 1.5). This

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.