Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
JQuery keeps sending me to the top of the page
Old 06-12-2009, 01:37 AM JQuery keeps sending me to the top of the page
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
I have a a fixed div that follows the user as they scroll down. The problem is every time they click on something in that div that has a jQuery function like showing a hidden div it'll send the user to the top of the page. Any way of fixing that?

Code:
$(document).ready(function() {
    
    $('div#panel').hide();
    
    // Expand Panel
    $("#open").click(function(){
        $("div#panel").slideDown("slow");
    
    });    
    
    // Collapse Panel
    $("#close").click(function(){
        $("div#panel").slideUp("slow");    
    });        
    
    // Switch buttons from "Log In | Register" to "Close Panel" on click
    $("#toggle a").click(function () {
        $("#toggle a").toggle();
    });        
        
});
MoForce is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-12-2009, 01:50 AM Re: JQuery keeps sending me to the top of the page
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
ROFLMAONADE!!!!

It's just one of those it's 1AM and I'm tired things

The error was in my <a id="open" class="open"> things i also had href="#"
MoForce is offline
Reply With Quote
View Public Profile
 
Old 06-12-2009, 08:49 AM Re: JQuery keeps sending me to the top of the page
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,987
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
just FYI, you could keep the href="#" and do this to your function to stop the jumping:
Code:
 $("#open").click(function(){
        $("div#panel").slideDown("slow");
        return false;//stops the default action
});
Even though jQuery uses the advanced event model, allowing for multiple same-type events on single elements, it allows you to return false just like the traditional event model, to stop the default action from taking place. This can be useful, since the href attribute can be used to send messages to the status bar, and will automatically make the cursor into the hand.
__________________
I build web things. I work for the startup
Please login or register to view this content. Registration is FREE
.
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 06-13-2009, 11:42 AM Re: JQuery keeps sending me to the top of the page
MoForce's Avatar
Super Talker

Posts: 145
Name: Jack Shalt
Trades: 0
Quote:
Originally Posted by wayfarer07 View Post
just FYI, you could keep the href="#" and do this to your function to stop the jumping:
Code:
 $("#open").click(function(){
        $("div#panel").slideDown("slow");
        return false;//stops the default action
});
Even though jQuery uses the advanced event model, allowing for multiple same-type events on single elements, it allows you to return false just like the traditional event model, to stop the default action from taking place. This can be useful, since the href attribute can be used to send messages to the status bar, and will automatically make the cursor into the hand.
Hmmm I did not know that. I'll try it out!

Thanks!
MoForce is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to JQuery keeps sending me to the top of the page
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.15593 seconds with 12 queries