Jump to content
Killersites Forums

JQUERY onClick Help


Recommended Posts

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??

Link to post
Share on other sites

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?

Link to post
Share on other sites

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.

Link to post
Share on other sites

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');

});

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...