I’m using this from Jquery Mobile to check whether an element clicked was a link:
function findClosestLink(ele) {
var self = this;
while (ele){
if (ele.nodeName.toLowerCase() == "a"){
break;
}
ele = ele.parentNode;
}
return ele;
}
It’s being called like this:
$(document).addEventListener( "click", function( e ){
var link = $( findClosestLink(e.target) );
console.log(link);
// routine
});
Queston:
When clicking on screen, the function returns an empty array []. I’m trying to check for this using
if (!link) {
return;
}
But this doesn’t work. How do I check for []?
Thanks for help!
Try
If no link is found, then length will be 0.