Variable Visions

Articles jQuery jQuery-opening-and-closing-read-more-box


tutorials - jQuery and Web-Development.

jQuery opening and closing read more box

Published Fri. Feb. 22, 2013


Use toogleClass with height: 0 to height: auto CSS rules, and use .text to toggle Show/Hide text.

                jQuery('.accordianholderbutton').click(function() {
                    jQuery(this).find('+ div').toggleClass('accordianholder2');
                    jQuery('.accordianholderbutton').toggleClass('accordianholderbutton2');
                    jQuery(this).text(jQuery(this).text() == 'Click here for less information' ? 'Click here for more information' : 'Click here for less information');
                });  

 

                jQuery.extend($.fn.disableTextSelect = function() {
                        return this.each(function(){
                        if($.browser.mozilla){
                            $(this).css('MozUserSelect','none');
                        }else if($.browser.msie){
                            $(this).bind('selectstart',function(){return false;});
                        }else{
                            $(this).mousedown(function(){return false;});
                        }
                    });
                });
                $('.accordianholderbutton').disableTextSelect();
               


<div class="accordianholderbutton">Click here for more information</div>

<div class="accordianholder">
<p>Lorem Ipsum Dolor.</p>
</div>


.accordianholderbutton {
    background:url(http://store.interstateproducts.com/images/arrow-sprite.png) #f9d444 no-repeat right -3px;
    padding:10px 10px 10px 20px;
    cursor:pointer;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    color: #000;
}
.accordianholderbutton:hover {
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.8) !important;
}
.accordianholderbutton2 {
    background:url(http://store.interstateproducts.com/images/arrow-sprite.png) #f9d444 no-repeat right -38px;
    color: #FFF;
}
.accordianholder {
    height:0px;
    overflow:hidden;
}
.accordianholder2 {
    height:auto !important;
}


Tag(s): jQuery, .toggleClass, .text,