Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 08-15-2012, 04:05 PM   #1
Lace
Too lazy to set a custom title
 
Lace's Avatar
 
Industry Role:
Join Date: Mar 2004
Posts: 16,116
Need some quick jQuery help

Trying to code up a page to hide content on load, but expand once the header is clicked.

First header works, but the second and third are not at the moment. I need probably 15 different headers here. I'm no jQuery expert by far.

http://barcritic.com/toggle3.html

Anyone see what I'm doing wrong here?

Code:
$(document).ready(function(){
	$("#expanderHead").click(function(){
		$("#expanderContent").slideToggle();
		if ($("#expanderSign").text() == "+"){
			$("#expanderSign").html("−")
		}
		else {
			$("#expanderSign").text("+")
		}
	});
});
Code:
<h4 id="expanderHead">
	HEADER 1 <span id="expanderSign">+</span>
</h4>
<div id="expanderContent" style="display:none">
TEXT HERE
</div>


<h4 id="expanderHead">
	HEADER 2 <span id="expanderSign">+</span>
</h4>
<div id="expanderContent" style="display:none">
TEXT HERE
</div>


<h4 id="expanderHead">
	HEADER 3 <span id="expanderSign">+</span>
</h4>
<div id="expanderContent" style="display:none">
TEXT HERE
</div>
__________________
Your Paysite Partner
Strength In Numbers!
StickyDollars | RadicalCash | KennysPennies | HomegrownCash

Last edited by Lace; 08-15-2012 at 04:07 PM..
Lace is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-15-2012, 04:15 PM   #2
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,066
I am not a jquery expert but I think your problem is because of duplicate ids. I do believe that ids need to be unique.

Just a quick guess.

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-15-2012, 04:18 PM   #3
Lace
Too lazy to set a custom title
 
Lace's Avatar
 
Industry Role:
Join Date: Mar 2004
Posts: 16,116
Quote:
Originally Posted by sarettah View Post
I am not a jquery expert but I think your problem is because of duplicate ids. I do believe that ids need to be unique.

Just a quick guess.

.
Writing duplicate script and css with different ID's would be quite tedious, extensive and overkill though. I have another example without the - / +, but I need that.


Here's the other one.
Code:
jQuery(document).ready(function() {
  jQuery(".content").hide();
  //toggle the componenet with class msg_body
  jQuery(".heading").click(function()
  {
    jQuery(this).next(".content").slideToggle(500);
  });
});
__________________
Your Paysite Partner
Strength In Numbers!
StickyDollars | RadicalCash | KennysPennies | HomegrownCash

Last edited by Lace; 08-15-2012 at 04:20 PM..
Lace is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-15-2012, 04:21 PM   #4
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,066
Quote:
Originally Posted by Lace View Post
Writing duplicate script and css with different ID's would be quite tedious, extensive and overkill though. I have another example without the - / +, but I need that.
I have dome similar coding with just straight javascript and passing an id into a function.

I have not used jquery much though so I am not sure of the best way to do it there.

Doing it with just javascript on the onclick is fairly easy.


.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-15-2012, 04:26 PM   #5
Lace
Too lazy to set a custom title
 
Lace's Avatar
 
Industry Role:
Join Date: Mar 2004
Posts: 16,116
Hmm...going to try this http://jsfiddle.net/sYwER/5/

Just might work for what I need.

Edit: Nope, unordered and ordered lists are not hidden.
__________________
Your Paysite Partner
Strength In Numbers!
StickyDollars | RadicalCash | KennysPennies | HomegrownCash

Last edited by Lace; 08-15-2012 at 04:32 PM..
Lace is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-15-2012, 05:16 PM   #6
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,066
Quote:
Originally Posted by Lace View Post
Hmm...going to try this http://jsfiddle.net/sYwER/5/

Just might work for what I need.

Edit: Nope, unordered and ordered lists are not hidden.
Taking what you had and then a little from what you found:

Script:

Code:
$(document).ready(function(){
	$(".head").click(function(){
		$(this).find(".expanderContent").slideToggle();
		if ($(this).find(".expanderSign").text() == "+"){
			$(this).find(".expanderSign").html("−")
		}
		else {
			$(this).find(".expanderSign").text("+")
		}
	});
});
Changed up the html a touch to wrap each of your sections in a div:

Code:
<div class=head>
<h4 class="expanderHead">
	HEADER 1<span class="expanderSign">+</span>
</h4>
<div class="expanderContent" style="display:none">
TEXT HERE
</div>
</div>

<div class=head>
<h4 class="expanderHead">
	HEADER 2 <span class="expanderSign">+</span>
</h4>
<div class="expanderContent" style="display:none">
TEXT HERE
</div>
</div>

 <div class=head>
<h4 class="expanderHead">
	HEADER 3 <span class="expanderSign">+</span>
</h4>
<div class="expanderContent" style="display:none">
TEXT HERE
</div>
</div>
http://madspiders.com/divtest.htm
__________________
All cookies cleared!

Last edited by sarettah; 08-15-2012 at 05:18 PM..
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 08-15-2012, 05:36 PM   #7
Lace
Too lazy to set a custom title
 
Lace's Avatar
 
Industry Role:
Join Date: Mar 2004
Posts: 16,116
Awesome!!! Thanks, sarettah!
__________________
Your Paysite Partner
Strength In Numbers!
StickyDollars | RadicalCash | KennysPennies | HomegrownCash
Lace is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.