I'm using event delegation (http://www.danwebb.net/2008/2/8/event- delegation-made-easy-in-jquery) to capture events that have bubbled up to the #nav element. It might even make sense to capture clicks that bubble up to the document object. I want to use the .is function to figure out what the user clicked on. Can I pass selector expressions like "div div#nav a.exit" to the .is function?
On Feb 20, 2:18 pm, Hamish Campbell <[EMAIL PROTECTED]> wrote: > Your jQuery is a bit faulty. You've only applied the event to the div > called nav, not to the links. Also, you don't need to use event.target > - the function will fire with this == the bound element. > > Try: > > <div id="nav"> > <a href="/exit/" class="exit">Exit</a> > <a href="/open/" class="open">Open</a> > </div> > > <script type="text/javascript" charset="utf-8"> > jQuery(document).ready(function(){ > jQuery('#nav a').bind('click', function() { > alert(jQuery(this).is('.exit')); > return false; > });}); > > </script> > > On Feb 21, 7:10 am, hartshorne <[EMAIL PROTECTED]> wrote: > > > Hi, I'm new to jQuery, and found something unexpected. With something > > like this: > > > <div id="nav"> > > <a href="/exit/" class="exit">Exit</a> > > <a href="/open/" class="open">Open</a> > > </div> > > <script type="text/javascript" charset="utf-8"> > > jQuery('#nav').bind('click', function() { > > alert(jQuery(event.target).is('#nav .exit')); > > event.preventDefault();}); > > > </script> > > > I expect .is('#nav .exit') to return true when the event is fired from > > the Exit link, and false otherwise. Instead it always returns true. > > What am I missing? > > > Thanks!