[jQuery] Re: $(this) and bind()? Noobish questions...
$(this).find(.thumb).animate({ height: 50px }, fast); Another way is to use the context argument of jQuery: $(.thumb, this); I believe this will actually be more performant because it only uses one call to jQuery rather than two. -- Josh
[jQuery] Re: $(this) and bind()? Noobish questions...
Hi Matt and Tobaco, thanks for the quick replies -- I really appreciate the help! :) Both of your replies have been very helpful. Thanks! Have a great day! Cheers, Micky On Jan 24, 7:54 pm, Micky Hulse [EMAIL PROTECTED] wrote: Hi, Two quick questions: - 01. $(.item).hover( function() { console.log(this); /* For Firebug. */ $(this + ' .thumb').animate({ height: 50px }, fast); /* How to target a child element of $(this)? */}, function() { console.log(this); /* For Firebug. */ $(this + ' .thumb').animate({ height: 25px }, fast); /* How to target a child element of $(this)? */} ); So, $(this + ' .thumb') does not work (to be expected)... But how can I make sure I target the child element $(.thumb) of $(this)? Here is the HTML: div class=item div class=thumb/div /div - 02. I am trying to learn when I should use bind() in my jQuery coding... Would I want to bind() the hover via the above code snippet? - Tips would be spectacular! :D Thanks a million in advance. Cheers, Micky
[jQuery] Re: $(this) and bind()? Noobish questions...
Micky, On .bind(), I'm afraid I'm in the same boat as you; total n00b, so I'm afraid I can't offer much help there. On the child selection, the selector that immediately comes to mind is parent child. I could be mistaken, but I don't think you'll be able to use 'this', as it is a reference to the actual object. So, it'd be something like so: $(#myElementSelector div.thumb).animate({ height: 50px }, fast); For more info, check the selectors info in the docs: http://docs.jquery.com/Selectors HTH Matt
[jQuery] Re: $(this) and bind()? Noobish questions...
hi, for 01. try this: $(this).find(.thumb).animate({ height: 50px }, fast); for 02.: hover is just a helper-function. it simplifies the process of binding. see this example from the blog-entry (http://jquery.com/blog/ 2008/01/15/jquery-122-2nd-birthday-present/) for the latest jquery- release: $(li).hover(function(){ $(this).addClass(hover); }, function(){ $(this).removeClass(hover); }); $(li).bind(mouseenter, function(){ $(this).addClass(hover); }).bind(mouseleave, function(){ $(this).removeClass(hover); }); they do both the same. greetings, torsten On 25 Jan., 04:54, Micky Hulse [EMAIL PROTECTED] wrote: Hi, Two quick questions: - 01. $(.item).hover( function() { console.log(this); /* For Firebug. */ $(this + ' .thumb').animate({ height: 50px }, fast); /* How to target a child element of $(this)? */}, function() { console.log(this); /* For Firebug. */ $(this + ' .thumb').animate({ height: 25px }, fast); /* How to target a child element of $(this)? */} ); So, $(this + ' .thumb') does not work (to be expected)... But how can I make sure I target the child element $(.thumb) of $(this)? Here is the HTML: div class=item div class=thumb/div /div - 02. I am trying to learn when I should use bind() in my jQuery coding... Would I want to bind() the hover via the above code snippet? - Tips would be spectacular! :D Thanks a million in advance. Cheers, Micky