Which is better to use and why?
if ($(target).parents('div#test').length) {
or
var target = $(evt.target);
if (target.parents('div#test').length){
Which is better to use and why?
if ($(target).parents('div#test').length) {
or
var target = $(evt.target);
if (target.parents('div#test').length){
There are preformance gains to be had in using the second option. If you are going to reuse the selector multiple times.
Essentially you are caching your DOM traversal if you use the same selector multiple times.
See this answer for more details