Friday, September 12, 2014

Making jQuery and Boostrap 3 and "hide" class work together

One of the problems with using jQuery's show and hide methods is that they are not compatible with the provided Bootstrap css classes "show" and "hide".

What is the problem? Bootstrap's css class looks like this:



.hide {
  displaynone !important;
}

Those important styles are necessary on some elements to make the behavior as expected. However, jQuery doesn't overwrite them when setting css attributes with the built-in show/hide methods. The recommended way that I found is to manually use .addClass("hide") and .removeClass("hide")...which is way too annoying.



Add the following JavaScript code after the initial jQuery .js file load and all is well.

var originaljQueryShow = jQuery.fn.show;
var originaljQueryHide = jQuery.fn.hide;
jQuery.fn.extend({
    show: function () {
        var result = originaljQueryShow.apply(this, arguments);
        jQuery(this).removeClass("hide");
        return result;
    },
    hide: function () {
        var result = originaljQueryHide.apply(this, arguments);
        jQuery(this).addClass("hide");
        return result;
    }
});


This lets the original functionality of the jQuery show() and hide() to be maintained, while adding transparent support for the Bootstrap css hide class.

7 comments:

wdmtest

jQuery
jQuery Basics
Including the jQuery Library Code in an HTML Page Problem
Executing jQuery/JavaScript Coded After the DOM Has Loaded but Before Complete Page Load
Selecting DOM Elements Using Selectors and the jQuery Function
Selecting DOM Elements Within a Specified Context
Filtering a Wrapper Set of DOM Elements
Finding Descendant Elements Within the Currently Selected Wrapper Set
Returning to the Prior Selection Before a Destructive Change
Including the Previous Selection with the Current Selection

kingrani

Flipkart is Offering Cashback Offers Flipkart Cashback Offer You will get upto 75% Discount

Flipkart is Offering Cashback Offers Flipkart Cashback Offers You will get upto 75% Discount

Flipkart is Offering Cashback Offers Flipkart big billion day offers You will get upto 75% Discount

Flipkart is one of the biggest world wide eCommerce Site so here you will getFlipkart big billion day offers

Flipkart is one of the biggest world wide eCommerce Site so here you will getflipkart bank cashback offersso

Flipkart is one of the biggest world wide eCommerce Site so here you will getFlipkart bank offersso

AJ Nishant

Nice blog. Thanks for sharing such informative blog.

Education Information Portal

Superb post. Impressive writing skill. Thank u so much for sharing with us.
Selection Process of Police Govt Jobs

Mahesh chaube

Great article admin. i love the way you summarized this post.

lots of love from: Ramadan Song

krishna kumar


Amazon cashback offers 2018Cashback Deals with sbi,hdfc,icici,axis banks,credit&debit card,
Amazon Cashback Offers 2018 Upto 65% Cashback Deals, AMAZON CASHBACK OFFERS 2018, DISCOUNT COUPON OFFERS 2018, Amazon cashback offers with sbi hdfc icici axis banks credit&debit card offers more. amazon cashback offers2018,amazon india cashback,amazon offers on mobiles,amazon cashback2018,amazon offers 2018



cashbackoffer amazon coupon code| amazon coupon promo code| amazon offer coupon code|
amazon coupon code| amazon coupon promo code| amazon offer coupon code


About Airport Parking,Accor HotelsAffordable Asia,Agoda,Air Asia Go,Akbar Travels,Amoma,Azores Getaways,Big Bus Tours,Booking,CarmelLimo,CatchThatBus,CheapAir,CheapTickets Singapore,Cleartrip,Ctrip English speaking,Etihad Airways,Expedia,Expedia India, Expedia Indonesia Hotels, Flights & Packages,Travel Coupons, Offers: Flights, Hotels, Bus Promo Codes
accor HotelsAffordable Asia,Agoda,Air Asia Go,Akbar Travels,Amoma,Azores Getaways,Big Bus Tours,Booking,CarmelLimo,CatchThatBus,CheapAir,CheapTickets Singapore,Cleartrip,Ctrip English speaking,Etihad Airways,Expedia,Expedia India,

Expedia Indonesia Hotels, Flights & Packages

CashBack Offers, Discount Coupons, Bank Offers & Promo Codes


flipkart cashback offer,
CashBack Offers, Discount Coupons


Pepperfry, Mobikwik, Firstcry, Fab Hotels, Ebay, Aliexpress, Adidas, Healthkart, Pepperfry, Shoppers Stop, FlipKart, Amazon, Lurap, Giftalove, Reebok, SBI Card, CoolWinks, Housejoy, Shine, Jaypore, netmeds, FabAlley, Prettysecrets, FlowerAura, Clovia, Shopclues, Printvenue, Firstcry, Travelguru, Myntra, Zivame, Jabong, Ferns N Petals,Healthkart, Pepperfry, Shoppers Stop, FlipKart, Amazon


CashBack Offers, Discount Coupons, Bank Offers & Promo Codes

krishna kumar


Amazon cashback offers 2018Cashback Deals with sbi,hdfc,icici,axis banks,credit&debit card,
Amazon Cashback Offers 2018 Upto 65% Cashback Deals, AMAZON CASHBACK OFFERS 2018, DISCOUNT COUPON OFFERS 2018, Amazon cashback offers with sbi hdfc icici axis banks credit&debit card offers more. amazon cashback offers2018,amazon india cashback,amazon offers on mobiles,amazon cashback2018,amazon offers 2018



cashbackoffer amazon coupon code| amazon coupon promo code| amazon offer coupon code|
amazon coupon code| amazon coupon promo code| amazon offer coupon code


About Airport Parking,Accor HotelsAffordable Asia,Agoda,Air Asia Go,Akbar Travels,Amoma,Azores Getaways,Big Bus Tours,Booking,CarmelLimo,CatchThatBus,CheapAir,CheapTickets Singapore,Cleartrip,Ctrip English speaking,Etihad Airways,Expedia,Expedia India, Expedia Indonesia Hotels, Flights & Packages,Travel Coupons, Offers: Flights, Hotels, Bus Promo Codes
accor HotelsAffordable Asia,Agoda,Air Asia Go,Akbar Travels,Amoma,Azores Getaways,Big Bus Tours,Booking,CarmelLimo,CatchThatBus,CheapAir,CheapTickets Singapore,Cleartrip,Ctrip English speaking,Etihad Airways,Expedia,Expedia India,

Expedia Indonesia Hotels, Flights & Packages

CashBack Offers, Discount Coupons, Bank Offers & Promo Codes


flipkart cashback offer,
CashBack Offers, Discount Coupons


Pepperfry, Mobikwik, Firstcry, Fab Hotels, Ebay, Aliexpress, Adidas, Healthkart, Pepperfry, Shoppers Stop, FlipKart, Amazon, Lurap, Giftalove, Reebok, SBI Card, CoolWinks, Housejoy, Shine, Jaypore, netmeds, FabAlley, Prettysecrets, FlowerAura, Clovia, Shopclues, Printvenue, Firstcry, Travelguru, Myntra, Zivame, Jabong, Ferns N Petals,Healthkart, Pepperfry, Shoppers Stop, FlipKart, Amazon


CashBack Offers, Discount Coupons, Bank Offers & Promo Codes