how i can check in this code that the parent in loop is span or div.
$('a img, span img').each(function(n){
var c= $(this).parent();
console.warn(c)
});
i want to know if this possible to check that find the parent tag is span or anchor in html
how i can check in this code that the parent in loop is span or div.
$('a img, span img').each(function(n){
var c= $(this).parent();
console.warn(c)
});
i want to know if this possible to check that find the parent tag is span or anchor in html
You can use
is:The
ismethod returnstrueif any of the selected elements match the selector. In this case, the selected element is the parent, and the selector looks for either aspanor anaelement.Alternatively, you could use
parentwith a selector and check the length of the resulting object:The
ismethod is marginally faster though (don’t be misled by the apparently huge difference… the numbers are both quite low):