Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-05-2012, 01:44 PM   PM User | #1
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 129
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
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");
}
m2244 is offline   Reply With Quote
Old 10-05-2012, 01:59 PM   PM User | #2
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 129
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
Well, I guess I fixed it, not sure why 'return false' fixes it though.

Code:
$('a.glossaryLink').live("click", function(event){
		onRollOverPULink();
		return false;
	});
m2244 is offline   Reply With Quote
Old 10-05-2012, 02:04 PM   PM User | #3
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,706
Thanks: 5
Thanked 876 Times in 851 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
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.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 10-05-2012, 02:21 PM   PM User | #4
m2244
Regular Coder

 
Join Date: Jun 2012
Posts: 129
Thanks: 1
Thanked 1 Time in 1 Post
m2244 is an unknown quantity at this point
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.
m2244 is offline   Reply With Quote
Old 10-05-2012, 02:53 PM   PM User | #5
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
you can control the cursor style for any element you like, using css:

Code:
<style>
span{
cursor:pointer;
}
</style>
xelawho is online now   Reply With Quote
Old 10-05-2012, 06:11 PM   PM User | #6
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,337
Thanks: 13
Thanked 207 Times in 207 Posts
DanInMa is on a distinguished road
Code:
$('a.glossaryLink').live("click", function(event){
       event.preventDefault();
		onRollOverPULink();

	});
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 02:32 PM.


Advertisement
Log in to turn off these ads.