Hi hartshorne,

You're on the right track with event delegation as it is fundamentally
different than binding the event to each link. With event delegation you
have 1 event bound to 1 element (div), in binding to each link you have 1
event boud to two links.


jQuery('#nav').bind('click', function(evt) {
   // this is a reference to #nav so we can certify that
event.targetoccurred on one of it's children
   alert(jQuery(evt.target).is('.exit'));
   // Call this against the event passed in as the first argument (evt)
   evt.preventDefault();
});

That should do what you're looking for

Cheers,
-Jonathan


On 2/20/08, 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!
>

Reply via email to