Home › Forums › JavaScript › jQuery "return false"
- This topic is empty.
-
AuthorPosts
-
March 17, 2009 at 6:48 am #24360
Historical Forums User
ParticipantI’m trying Chris’ tutorial #20. It is below all the widgets http://www.aaronheine.com
I had to add "return false" to keep the links from making the page jump to the top of the browser. But the first link is not working with "return false" Am I entering it correctly? I tried a couple different ways.
Code:jQuery(document).ready(function() {
jQuery(“li.action-one”).click(function(){
jQuery(“#page-wrap2”).animate({
width: “300px” return false;});
});
jQuery(“li.action-two”).click(function(){
jQuery(“p”).toggle(); return false;});
jQuery(“li.action-three”).click(function(){
jQuery(“#header2”).slideUp(); return false;});
});Thanks
March 17, 2009 at 10:33 am #55067Rob MacKay
Participantyou could try…
Code:jQuery(document).ready(function() {
jQuery(“li.action-one”).click(function(){
jQuery(“#page-wrap2”).animate({
width: “300px”
});
return false;
});jQuery(“li.action-two”).click(function(){
jQuery(“p”).toggle();});
return false;
jQuery(“li.action-three”).click(function(){
jQuery(“#header2”).slideUp();});
return false;
});
March 18, 2009 at 3:25 am #55098Historical Forums User
ParticipantNow it is not working at all. :( Seems like there are a lot of quirks to working with jquery/PHP. This is my entire header if you want to give it another try.
Thanks
Code:Rob MacKay
Participantyea it was a random stab in the dark as to say lol – I shall have another look, cant promise anythin though :)
March 18, 2009 at 6:17 am #55108Rob MacKay
ParticipantOk this works for me…
Code:jQuery(document).ready(function() {jQuery(“li.action-one”).click(function(){
jQuery(“#page-wrap2”).animate({
width: “300px”
});
return false;
});jQuery(“li.action-two”).click(function(){
jQuery(“p”).toggle();
return false;
});jQuery(“li.action-three”).click(function(){
jQuery(“#header2”).slideUp();
});
return false;
});Just to point out you had an extra ";" after your width: "300px" – so I took that out and it removed an error :)
April 11, 2009 at 6:22 am #56127jackfranklin
MemberAn easier way is to pass the event throught the function and use the preventDefault function in jQuery:
Code:$(“li”).click(function(event) {
event.preventDefault(); //link wont go to destination now
..do the rest of your stuff…
});AuthorPostsViewing 6 posts - 1 through 6 (of 6 total)- The forum ‘JavaScript’ is closed to new topics and replies.