This still doesn't work, I've stripped it down to this:
$(document).click(function(e) { var $linkClicked = $(e.target); if( $linkClicked.is("a") ) { alert("Hi"); return false; } }); but nothing registers, the return false doesn't work and neither is there an alert. Here's the relevant jquery in full: $(document).ready(function() { ////////////////////////////////////////////////////////////////// CHECK URL var pageHash = window.location.hash.substr(1); if( pageHash == "" ) // If empty open HOME { openPage("home"); } else { openPage(pageHash); // Else open relevant } watchLinks(); // Watch the links pictureIt('graphics/bg/ploughedfield.jpg'); }); //////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// WATCH LINKS function watchLinks() { $(document).click(function(e) { var $linkClicked = $(e.target); if( $linkClicked.is("a") ) { var youWantToGoTo = $linkClicked.attr('href').substr(0,$(this).attr('href').length-4); // Determine destination openPage(youWantToGoTo); // Open destination window.location.hash = youWantToGoTo; // Set the url # return false; } }); }; }); }; malsup wrote: > > >> I've read through both the link you suggested >> andhttp://www.tvidesign.co.uk/blog/improve-your-jquery-25-excellent-tips... >> but I can't understand how I would make event delegation work for me. >> >> This is what I attempted: >> >> function watchLinks() >> { >> $("a").click(function(e) >> { >> var linkClicked = $(e.target); >> if( linkClicked.is("a")) >> { >> var youWantToGoTo = >> linkClicked.attr('href').substr(0,$(this).attr('href').length-4); // >> Determine destination >> openPage(youWantToGoTo); // Open destination >> window.location.hash = youWantToGoTo; // Set the url # >> return false; >> } >> }); >> }; > > > Don't bind the anchors, bind the document: > > $(document).click(function(e) { > var $el = $(e.target); > if ($el.is('a')) { > var href = $el.attr('href'); > var hash = href.substr(0,href.length-4); > openPage(hash); > window.location.hash = hash; > return false; > } > }); > > -- View this message in context: http://www.nabble.com/.load%28%29-callback-tp21389522s27240p21398423.html Sent from the jQuery General Discussion mailing list archive at Nabble.com.