Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-09-2012, 02:22 PM   PM User | #1
newbie22
New to the CF scene

 
Join Date: Feb 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
newbie22 is an unknown quantity at this point
Question error in simple hide/show text in javascript

Code:
<html>
<title> random!!</title>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.min.js"></script>
</head>
<body>
<div class="one" style="cursor: pointer;">
type1<br/><br/></div><div class="two" style="cursor: pointer;">type2<br/><br/></div><div class="three" style="cursor: pointer;">type3<br/><br/></div>
<div class="oneone">atrdjgkhgfyfygfykfyfkygfvkgvkhgv</div><div class="twotwo">hgfihygohgohsgoihgolhgshgoshdgchchj</div><div class="threethree">siucgdiuhsbcohbscjbsidjcksjdnck</div>

<script type="text/javascript"> 
$(document).ready(function() 
{ 
$('div.twotwo').hide();
$('div.threethree').hide(); 
$('div.one').toggle(function() 
{
$('div.twotwo').hide();
$('div.threethree').hide();
$('div.oneone').fadeIn('slow'); 
}, function() 
{ 
return false; 
}); 

$('div.two').toggle(function() 
{
$('div.oneone').hide();
$('div.threethree').hide();
$('div.twotwo').fadeIn('slow'); 
}, function() 
{ 
return false; 
}); 

$('div.three').toggle(function() 
{
$('div.twotwo').hide();
$('div.oneone').hide();
$('div.threethree').fadeIn('slow'); 
}, function() 
{ 
return false; 
}); 
});
</script>
</body>
</html>
The following code works perfectly when clicked once in each of the sub divisions(type1, type2, type3) for hide/show. But from the next time onwards we will have to click twice to initiate the hide/show. Can anyone suggest changes to make the code work as desired??.. P.S: sorry if i have made any stupid mistake.. i am quite new to this!!
newbie22 is offline   Reply With Quote
Old 02-09-2012, 03:17 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
Hm this is weird ... I did not find any .toggle() method in jQuery that takes two callback functions. The normal usage is
Code:
.toggle(duration, [easing, [callback]])
Which means, the first parameter has to be a number or string determining the speed of the toggle process. So I guess your usage is flawed.
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Tags
debugging, error, hide/show, javascript, simple

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:05 AM.


Advertisement
Log in to turn off these ads.