Jump to content

Recommended Posts

Posted

hello, i am working on a script that will show more information......

 

I can't figure out how to do on 2nd click function......

 

here is my code:

 

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

	$('#wrap').css('height','100%');

	$('.togglecontent').toggle('slow', function(){
		//this is even
		$('#wrap').css('height','200px');
	}, function(){
		//this is odd
		$('#wrap').css('height','200px');
	});

});

 

What i am trying to do is make the "#wrap" go back to 200px; when the user clicks the ".morebutton" for the 2nd time.

 

Any ideas on how to do this??

Posted

Have you tried this?

 

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

               $('.togglecontent').toggle('slow', function(){
                       //this is even
                       $('#wrap').css('height','100%');
               }, function(){
                       //this is odd
                       $('#wrap').css('height','200px');
               });

       });

Posted

i'm running this code right now:

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

	$('#wrap').css('height','100%');

	$('.togglecontent').toggle('slow');

});

 

But i need some way to change the css back to 200px; on the second click of the more button......any ideas?

Posted

You could always set a variable that gets 1 added to it every time the click event is called. If the variable is even, set the height to one value, if it is odd, set it to something else.

 

Or use the height() function to find the current height of #wrap, and set the height based on whether the current height is 200px or not.

Posted

Great idea! i got it to work using the following:

var count = 0; //the click count begins

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

	count = count +1;
	if(count % 2 === 0){
		$('#wrap').css('height','200px');			
	}
	else{
		$('#wrap').css('height','100%');
	}
	$('.togglecontent').toggle('slow');

});

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...