Performance Tweaking

Performance Tweaking

So I read that caching selectors is a best practice, and I'm trying to update my script accordingly.

  1. //This is BAD
  2. $('#item li').css ('color', '#123456');  
  3. $('#item li').html ('hello');  
  4. $('#item li').css ('background-color', '#ffffff');  

  5. //This is GOOD
  6. var item = $('#item li');  
  7. item.css ('color', '#123456');  
  8. item.html ('hello');  
  9. item.css ('background-color', '#ffffff');  

My question is what if I have a lot of children to access, will caching improve performance in this case:

  1. //Method #1
  2. $('#item li h3').css ('color', '#123456');  
  3. $('#item li p#greeting').html ('hello');  
  4. $('#item li span').css ('background-color', '#ffffff');  

  5. //Method #2
  6. var item = $('#item li');  
  7. item.find("h3").css ('color', '#123456');  
  8. item.find("p#greeting").html ('hello');  
  9. item.find("span").css ('background-color', '#ffffff');

Is there ANY advantage of going with Method #2 over #1 here, or does the .find() selector negate any caching that is happening?  And does this also apply to .filter() ?

Thanks for any help!