Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript jQuery "return false"

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #24360

    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

    #55067
    Rob MacKay
    Participant

    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;

    });

    #55098

    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:

    >


    <?php bloginfo('name'); ?> <?php if ( is_single() ) { ?> » Blog Archive <?php } ?> <?php wp_title(); ?>

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




    #55104
    Rob MacKay
    Participant

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

    #55108
    Rob MacKay
    Participant

    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 :)

    #56127
    jackfranklin
    Member

    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)
  • The forum ‘JavaScript’ is closed to new topics and replies.