java onclick function for all links.

July 3, 2010 at 08:03:24
Specs: Windows XP
hi guys, I have asked this question before, and it may not be clear. Let me ask again, its very important for me thats why I am asking u despondently u. here it is
I have a function called load(). This function shows a loading sign when a link is clicked. But to associate links with this function I have to give d/f IDs for all links. I was wondering if it is possible to set that function for all links on the page with out giving every link a d/f Id. like some kind of function that would call load() for every link.
sorry to bosser u.
tnx in advance

See More: java onclick function for all links.

Report •

July 3, 2010 at 18:01:29
using jQuery:

$('a').each(function() {
load( $(this).attr('id') );

Report •

July 3, 2010 at 22:50:12
I think I have to give ids for this one too, right??

Report •

July 4, 2010 at 14:34:58
No, it selects elements just like CSS. So that would select every Anchor 'a', just like you'd do in CSS.


$('*') selects EVERY element on the page
$('a') selects all the anchors
$('') selects all anchors with class=link
$('#element') selects elements with ID=element
$('a[href$=.pdf]') selects Anchor elements who's HREF attribute ends in .PDF

jQuery selectors are very powerful. Read about them here -

Report •

Related Solutions

Ask Question