views:

39

answers:

3

I have some code right now that executes when a link is clicked. The HTML is structured:

<a href='link1'>Stuff<span class='color-bar'></span></a>
<a href='link2'>Stuff<span class='color-bar'></span></a>
<a href='link3'>Stuff<span class='color-bar'></span></a>

With the jQuery like so:

$('a').liveQuery('click',function(event){
  ...
  ...
  $( selector ).animate({bottom:10},'slow');
}

My question is how do I target the specific '.color-bar' using $this? Before I had each one assigned an id, but then realized it was overkill and figured I could do it using the $this element.

I tried $( $this > '.color-bar' ) but that didn't work. Am I just getting syntax wrong or approaching it incorrectly? Thanks!

+2  A: 

solution

$('.color-bar', $this)

or

$(this).find('.color-bar')

note

.find() is a bit faster than the first solution, because the first solution calls find anyway internally in jQuery. But it looks a bit more nice

Adam Kiss
Awesome! Thanks!
Bradley Herman
You can also mark me as answer ^^
Adam Kiss
For what it's worth, I tend to use the second form - my mind finds it easier to understand, and thus more maintainable, which always wins with similar/same results solutions.
Mark Schultheiss
A: 
$(this).find('.color-bar').animate({bottom:10},'slow');
Felix Kling
A: 
$(this).children('.color-bar').animate({bottom:10},'slow'); 
Mark Schultheiss