0

I have a jQuery which toggles a div on click.

$(document).ready(function() {
$('#showmenu').click(function() {
    $('#showmenu').text($('.sidebarmenu').is(':visible') ? 'Show Menu' : 'Hide Menu');
    $('.sidebarmenu').toggle("slide");
}); 
});

FIDDLE

How can I do the same without using

display:none;

??

Bittu
  • 387
  • 2
  • 6
  • 13

6 Answers6

1

Look at a offset based solution

<button id="showmenu" type="button">Show menu</button></div>
<div class="sidebarmenu" style="position: absolute; left: -200000px">

    Can the button value change to "show" or "hide"
</div>

then

$(document).ready(function() {
    $('#showmenu').click(function() {
        var hidden = $('.sidebarmenu').data('hidden');
        $('#showmenu').text(hidden ? 'Show Menu' : 'Hide Menu');
        if(hidden){
            $('.sidebarmenu').css({
                position: 'absolute',
                left: -200000
            })
        } else {
            $('.sidebarmenu').css({
                position: '',
                left: 0
            })
        }
        $('.sidebarmenu').data("hidden", !hidden);
    });
});

Demo: Fiddle

Arun P Johny
  • 384,651
  • 66
  • 527
  • 531
0

You can make use of visibility:hidden; css property which work same.

There is another alternative which is opacity set opacity:0

Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
  • @Itay on client side it perform same...isn't it..? – Dipesh Parmar Sep 03 '13 at 05:09
  • 1
    Nope. [What is the difference between visibility:hidden and display:none?](http://stackoverflow.com/questions/133051/what-is-the-difference-between-visibilityhidden-and-displaynone) – Itay Sep 03 '13 at 05:10
0

not sure if i got your question .. but i gues you can use hide().

 $('.sidebarmenu').hide();

inside your document.ready $(document).ready(function() { function

fiddle here

bipen
  • 36,319
  • 9
  • 49
  • 62
0

You can also place this using .show() and .hide()

($('#showmenu').is(':visible')) ? $('.sidebarmenu').show() 
                                : $('.sidebarmenu').hide();

And on page load hide the div like

$('.sidebarmenu').hide();

See the FIDDLE

GautamD31
  • 28,552
  • 10
  • 64
  • 85
0

To hide div u can use Visible="false" and to show use Visible="true"

Somnath Kharat
  • 3,570
  • 2
  • 27
  • 51
0
$(document).ready(function() {
$('#showmenu').click(function() {
    $('#showmenu').text($('.sidebarmenu').is(':visible') ? 'Show Menu' : 'Hide Menu');
    $('.sidebarmenu').toggle("show");
}); 
});
Amnishyadav
  • 21
  • 1
  • 4