Does it make sense to jQuery cache $(this)?

If you’re using it a lot, yes it makes sense, or chain, e.g.:

$(this).fadeIn().fadeOut().somethingElse();

If it expensive? No not really in the grand scheme of things…but if you’re in a loop the cost multiplies so it’s best to cache it. If you’re using it more than once it makes sense, how much sense depends on how much performance matters for that bit of code I suppose.

Leave a Comment