JavaScript Question

Pho3nix

The Legend
Joined
Jul 31, 2009
Messages
32,829
Reaction score
3,033
Location
On the toilet
Morning all :)

Need to unhide sections on the site but the code below doesn't work as only the 1st unhide works but the second soesn't. Any idea what Im doing wrong?


Code:
$("#show1").click(function () {
$("#div1").toggle("slow");
}); 

$("#show2").click(function () {
$("#div2").toggle("slow");
});
 
Morning all :)

Need to unhide sections on the site but the code below doesn't work as only the 1st unhide works but the second soesn't. Any idea what Im doing wrong?


Code:
$("#show1").click(function () {
$("#div1").toggle("slow");
}); 

$("#show2").click(function () {
$("#div2").toggle("slow");
});

/feels the StackOverflow panic setting in... :D

Could you maybe provide some sample of the actual page markup that you want to toggle the visibility of?

should you not be using?

$('#div1').toggleClass('whatever');

maybe see:
http://jqfundamentals.com/book/index.html#chapter-4
Not necessarily. The .toggle() function alters the CSS "display" property of the element to show or hide it, based on its current state. The .toggleClass() function adds / removes classes to the element. The .toggle() function would work just fine in this scenario...
 
Use FireBug or Chrome to inspect the HTML after the toggle worked the first time, and see if your container is triggering the action a second time or not. Perhaps some other element is covering "show2" after you've clicked "show1". Debug - always shows you the way.
 
Firebug fixed the issue. Seems the ID for Show2 wasn't set properly. Kinda freaked out lol, thanks guys for all your help.
OT : but slidetoggle() doesn't work on the page which is why I used toggle(); Any possible way this could be.
 
Top
Sign up to the MyBroadband newsletter
X