Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post

    Why does this function run twice on one click?

    I have a jQuery function that I finally got to work, the problem is that it seems to run twice, I get the alert twice. In FF it I get this alert up to 5 times!

    Code:
    <ul>
      <li>
        	(U) Spiral 1.5: <a class="glossaryLink" href="#">SCCVI</a> and <a class="glossaryLink" href="#">SCRI</a>  </li>
      <li> (U) Spiral 2:  <a class="glossaryLink" href="#">HBSS</a>  </li>
    </ul>
    Code:
    function setGlossLinkListeners()
    {
    	$('a.glossaryLink').live("click", function(event){
    		onRollOverPULink();
    	});
    }
    This function runs multiple times.
    Code:
    function onRollOverPULink() 
    {
    	alert("onRollOverPULink");
    }

  • #2
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post
    Well, I guess I fixed it, not sure why 'return false' fixes it though.

    Code:
    $('a.glossaryLink').live("click", function(event){
    		onRollOverPULink();
    		return false;
    	});

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,629
    Thanks
    6
    Thanked 1,002 Times in 975 Posts
    The best would be to remove the href attributes from the links in the first place. After all, you’re not linking anything anyway, so why the href? And when we’re thinking this further if a link isn’t linking anything, why have an anchor in the first place? These could very well be any type of element, e. g. spans.

  • #4
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post
    Quote Originally Posted by VIPStephan View Post
    The best would be to remove the href attributes from the links in the first place. After all, you’re not linking anything anyway, so why the href? And when we’re thinking this further if a link isn’t linking anything, why have an anchor in the first place? These could very well be any type of element, e. g. spans.
    I think that if I took the href out it I would get the hand cursor.

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,917
    Thanks
    56
    Thanked 545 Times in 542 Posts
    you can control the cursor style for any element you like, using css:

    Code:
    <style>
    span{
    cursor:pointer;
    }
    </style>

  • #6
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    Code:
    $('a.glossaryLink').live("click", function(event){
           event.preventDefault();
    		onRollOverPULink();
    
    	});


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •