Hi. > I hoped that $(window).click(...) could give me the > possibility to handle the new window.location on-the-fly but > unfortunately my bound function is called before the browser > jumps to the anchor, so that window.location is still outdated.
In the abstract this can be a very good choice for "assigning" handlers. If you're not used to doing it the syntax can be weird because you need to look at the event object which you might not have used before. This example isn't like yours exactly but could be a starting point: <html> <ul id="wrapper"> <li/> <li/> <li/> </ul> </html> <script> document.getElementById('wrapper').onclick = function(e){ //e.target is for firefox. IE calls it something else. if(e.target.nodeName=="LI"){ alert("you clicked on an LI"); } }; </script> Googling for event delegation will turn up more. I've used this for pages with thousands of DOM elements for the performance improvement. It can also make for a much more elegant application design. Now that I know about this I look for opportunities to use it, and am sometime very pleasantly surprised. I'm surprised event delegation is not more widely used and understood!!!! ------>Nathan > -----Original Message----- > From: jquery-en@googlegroups.com > [mailto:[EMAIL PROTECTED] On Behalf Of Alessandro Portale > Sent: Monday, April 23, 2007 1:05 PM > To: jQuery (English) > Subject: [jQuery] Alternative way of reacting to clicked link? > > > Hi, > > I have a page with about 12000 links in it. A few of these > links point to anchors on the same page. A function should be > called when those "intra page" links are clicked. > > $("[EMAIL PROTECTED]").click(...) seems to be too slow for some > browsers on some machines if 12000 links need to be filtered. > > I hoped that $(window).click(...) could give me the > possibility to handle the new window.location on-the-fly but > unfortunately my bound function is called before the browser > jumps to the anchor, so that window.location is still outdated. > > Does anybody know another way of on-the-fly reacting to a > link click which allows to access the new url? > > Thanks in advance, > Alessandro >