Grow your CSS skills. Land your dream job.

jQuery "return false"

  • # March 17, 2009 at 6:48 am

    I’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

    Rob
    # March 17, 2009 at 10:33 am

    you 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

    Now 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:
    < !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    >

    <br /> < ?php if (is_home()) { echo bloginfo('name');<br /> } elseif (is_404()) {<br /> echo '404 Not Found';<br /> } elseif (is_category()) {<br /> echo 'Category:'; wp_title('');<br /> } elseif (is_search()) {<br /> echo 'Search Results';<br /> } elseif ( is_day() || is_month() || is_year() ) {<br /> echo 'Archives:'; wp_title('');<br /> } else {<br /> echo wp_title('');<br /> }s<br /> ?><br />


    < ?php }?>



    < ?php wp_head(); ?>

    Rob
    # March 18, 2009 at 5:41 am

    yea it was a random stab in the dark as to say lol – I shall have another look, cant promise anythin though :)

    Rob
    # March 18, 2009 at 6:17 am

    Ok 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

    An 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…
    });
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".