jQuery: add border on hovered element but NOT parents

Posted by John Isaacks on Stack Overflow See other posts from Stack Overflow or by John Isaacks
Published on 2010-05-11T21:05:08Z Indexed on 2010/05/11 21:14 UTC
Read the original article Hit count: 161

Filed under:

I have this code:

var originalBorder = container.css("border");    
container.hover(function(event) {
            event.stopPropagation();
            $(this).css("border", "1px solid "+options.color);
       },function(){
            $(this).css("border", originalBorder);
       });

Which I am using to add a border to the currently hovered element. However for example if a span is inside a div they are both getting borders. I only want to target the span. I thought that adding event.stopPropagation() would do the trick (this is what I would do in Flex, which is what I am more used to) but I guess this is a live event which I dont even understand what that means. So basically how can target the youngest element without triggering the parents?

Thanks!!

© Stack Overflow or respective owner

Related posts about jQuery