> so when you have an anchor set as
> block, with a few spans to style text, it is hard to click on the
> actual anchor to give it the class.  Is this normal?

That is a normal reaction when using event delegation and its one of
the "difficulties" that Ariel was probably referring to. You'll need
to set up your event delegation to account for 1) clicking on the
actual anchor and 2) clicking on the child span tag.

You'll need to add a condition to your IF statement to account for the
span tags...When $target is a span, select its parent anchor element.

if ($target.is('.scroll a')) {
  $("a.selected").removeClass("selected");
  $(event.target).addClass("selected");
}
else if ($target.is('span')) {
  var $anchor = $target.parent('a');
  $("a.selected").removeClass("selected");
  $anchor.addClass("selected");
}

Brian

On Aug 26, 4:22 pm, hubbs <[EMAIL PROTECTED]> wrote:
> Hmmm, I take that back.  It still seems like the is() is able to
> select child elements of the anchor, so when you have an anchor set as
> block, with a few spans to style text, it is hard to click on the
> actual anchor to give it the class.  Is this normal?
>
> On Aug 26, 11:37 am, hubbs <[EMAIL PROTECTED]> wrote:
>
> > Thank you, that fixed it.
>
> > Is the limitation of is() a javascript limitation, or a jQuery
> > limitation?  Would this be coming in a new version of jQuery?
>
> > Also, with event delegation, would you recommending using it for all
> > event instances on a page?  I have a few places where a single click
> > event is added to an ID, and I figure it is really not necessary to
> > mess with event delegation there.
>
> > On Aug 26, 11:31 am, Ariel Flesler <[EMAIL PROTECTED]> wrote:
>
> > > Note that is() doesn't accept complex selectors (yet). The reason of
> > > your problems is probably this.
> > > Event delegation is surely the best approach, if you can live with its
> > > difficulties.
>
> > > --
> > > Ariel Fleslerhttp://flesler.blogspot.com
>
> > > On Aug 26, 2:31 pm, hubbs <[EMAIL PROTECTED]> wrote:
>
> > > > I am working to replace all of my uses of livequery with event
> > > > delegation (is this even a good idea?) and have a few questions.
>
> > > > I have a simple script that will add a "selected" class to a link when
> > > > it is clicked.  It does work using event delegation, but it seems that
> > > > it is not limiting it to anchor tags, but will also add the "selected"
> > > > class to any spans that are inside my anchor.  This seems strange, and
> > > > is not what I want, is something wrong with the following code?
>
> > > >  $('body').click(function(event) {
> > > >         var $target = $(event.target);
> > > >         if ($target.is('.scroll a')) {
> > > >             $("a.selected").removeClass("selected");
> > > >             $(event.target).addClass("selected");
> > > >         }
> > > >     });
>
>

Reply via email to