btw, hovers should be done with CSS unless there is some (necessary)
special efffect involved. Certainly would give you better performance.

On Dec 16, 11:57 am, stephen <barto...@gmail.com> wrote:
> Hi,
>
> Actually this did work!! I did the same for the mouseout:
>
>         $('div.datarows').mouseout(function(event) {
>           var $thisRow, $tgt = $(event.target);
>           if ($tgt.is('div.row')) {
>             $thisCell = $tgt;
>           } else if ($tgt.parents('div.row').length) {
>             $thisCell = $tgt.parents('div.row:first');
>           }
>           // now do something with $thisCell
>           $thisCell.removeClass("row_highlight");
>         });
>
> and it works like a dream with no errors. Thanks for your help.
>
> Stephen
>
> On Dec 16, 1:33 pm, stephen <barto...@gmail.com> wrote:
>
> > Thanks guys for the pointer. I had never actually heard of event
> > delegation before. Every day is a school day. So, I read the article
> > and I was keen to implement it to try and solve my problem. But I
> > think I have a couple of conceptual leaps I need help with.
>
> > For my row highlighting to work, I need two events (mouseover and
> > mouseout), so I thinking I am still going to need two functions? So I
> > had a go at the mouseover one (see below), but it did not work. You
> > guys who have a little more experience of this than me, can you see
> > what I am doing wrong?
>
> > From this:
> >   $(".row").mouseover(function() {
> >     $(this).addClass("row_highlight");
> >   });
>
> > To this:
> >         $('div.datarows').mouseover(function(event) {
> >           var $thisRow, $tgt = $(event.target);
> >           if ($tgt.is('div.row')) {
> >             $thisCell = $tgt;
> >           } else if ($tgt.parents('div.row').length) {
> >             $thisCell = $tgt.parents('div.row:first');
> >           }
> >           // now do something with $thisCell
> >           $thisCell.addClass("row_highlight");
> >         });
>
> > Thanks in advance,
> > Stephen
>
> > On Dec 16, 12:43 pm, Mike Alsup <mal...@gmail.com> wrote:
>
> > > > You should have a look at event delegation, currently you are attaching 
> > > > 2
> > > > event on each row. So if you have a lot of rows, its memory/cpu heavy.
>
> > > I agree with Olivier.  Here's a resource to get you started:
>
> > >http://www.learningjquery.com/2008/03/working-with-events-part-1

Reply via email to