Jitendra Vyas Jitendra Vyas - 3 months ago 10
CSS Question

How to make one button for open and close div, in this jquery code?

$(document).ready(function(){

$('#content1').hide();

$('a#open').click(function(){

$('#content1').show('slow');

});

$('a#close').click(function(){
$('#content1').hide('slow');
})

});


in this code of toogle open and close button is different

<a>
and
<a id="close">


I want to make same button
<a>
for open and close and want to give different background image for open and close position

Kai Kai
Answer
$('a').click(function(){
  $('#content1').slideToggle();
});

If you would like to change their css ,you can re-write it in the following way.

$('a').click(function(){

       if ($('#content1').is(":visible"))
       {
            //change your css here
            //for eg. $(#content1).css('background-image', first_image);
            $('#content1').hide('slow');
       }
       else{ 
            //change your css here
            //for eg. $(#content1).css('background-image', second_image);
            $('#content1').show('slow');
       }

});
Comments