So I read that caching selectors is a best practice, and I'm trying to update my script accordingly.
- //Method #1
- $('#item li h3').css ('color', '#123456');
- $('#item li p#greeting').html ('hello');
- $('#item li span').css ('background-color', '#ffffff');
- //Method #2
- var item = $('#item li');
- item.find("h3").css ('color', '#123456');
- item.find("p#greeting").html ('hello');
- 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() ?