Hi Balazs, Thanks for the reply - looking at your suggestion, my idea was to apply it to the code like this:
$(function() { $("*").hover( function(){ // If the element has more than one child stop propagating. if ($(this).children().length() > 0) { return False } $(this).addClass('selected'); }, function(){ $(this).removeClass('selected'); } ); } This is _close_ to what I want, but what I'd really like is to grab DOM element you are hovering over with the minimum number of children - not necessarily zero. It's my understanding that with the above, if you hovered over a <p> with a <strong> inside you couldn't select the <p> because it would have a child! Thanks, John Should only return true if the selected $(this) has no children. This is _close_ to what I want - but what I'd really like is to grab the element On Sep 14, 4:10 am, Balazs Endresz <[EMAIL PROTECTED]> wrote: > Hey John, > > I think this will do that: > > $('body').find('*').filter(function(){ > return !$(this).children().length;}) > > .add('p').not('p *') //without this, if a paragraph contains tags > thehoverwon't be applied to the most of the text > > On Sep 12, 9:29 pm, John Boxall <[EMAIL PROTECTED]> wrote: > > > Heyo jQuery hackers, > > > I'm putting together a little script that adds a class "selected" to > > an element when youhoverover it. > > When you stop hovering the class "selected" class is removed. > > > I would like the class only to be apply to the lowest element in the > > DOM. > > > For example say I was hovering over a <p> deep inside a document - I > > would like to only add the class "selected" to that <p> tag, not the > > <div>, <body> and <html> tags surrounding it. > > > So far my thinking has been to use something like this: > > > $(function() { > > $("*").hover( > > function(){ > > $(this).addClass('selected'); > > }, > > function(){ > > $(this).removeClass('selected'); > > } > > ); > > > } > > > Which adds the "selected" class to any element Ihoverover fine. It > > also removes it. > > > The problem is thehoveris firing all the way up the chain and > > hitting all elements from the lowest to the highest so I've got a ton > > of ugly selected elements when I really just wanted the lowest one... > > > Is there any way I can restrict it? > > > Thanks, > > > John