tags:

views:

91

answers:

2

I have noticed a strange thing happening in jQuery and wonder if anyone knows why?

Upon clicking the following anchor tag

<A ID="catchme" HREF="#">Add Row</A>;,

my jQuery script will catch the click and display a hidden table row. The problem is the considerable lag to the redraw operation. Additionally, none of the animations will work on the element being displayed.

However, when I use a <DIV> or <SPAN> to catch the clicks (i.e. styled as a fake text link), the animations work a treat!!

I was also using e.preventDefault() on the HREF to stop it from following the HREF's link. Removing e.preventDefault() did not fix the problem.

This issue occurred on IE7 and FF3.5 using jQuery 1.3.2.

Does anyone know how to fix this issue from anchor tag clicks??

A: 

When writing the event handler, are you passing it the parameter of e? Example:

$('a').click(function(e){
     e.preventDefault();
});

Without passing the parameter e, the preventDefault() call is worthless.

cpharmston
Yes, I tried that. It seems to be an issue with listening to events on the anchor tag.
crunchyt
It likely isn't. An issue of that size on jQuery would never pass unit tests, let alone make it to production code. Can you edit your question to post your full code? Things I'd look for: whether your event binding is inside of a $(document).ready() call, whether the links are being added dynamically, etc.. Useful tools: Firebug's console object ( http://getfirebug.com/console.html ) and the Visual Event bookmarklet: ( http://www.sprymedia.co.uk/article/Visual+Event ).
cpharmston
+1  A: 

After much debugging, this turned out to be an undisplayed JavaScript deep in my own script stack. What may be of interest is that FireBug was deep sixing (ie. hiding) the error, However the Firefox Javascript console did in fact report the error!

Relying on Firebug as a single source of truth was my mistake ... lesson learned.

Thanks for those who tried to answer this one despite an insufficient description.

crunchyt
+1 for the single source of truth comment. Trust noone :-)
Dan F