I’m looping through the DOM from a link element to the closest element with class .ui-mobile-viewport. This can either be a DIV or the BODY element.
I need to check which element it is and am getting nowhere… this is what I’m trying:
var targetViewport;
// loop sets targetViewport as a $(‘div.ui-mobile-viewport’) or $(‘body.ui-mobile-viewport’)
if ( targetViewport === $('body') ) {
console.log("found a body");
}
Thanks for help!
Instead of doing the traversal yourself, you could try using the
.closest()method of jQuery. So I think you could do this:Now you have that
.ui-mobile-viewportelement as a jQuery object you can run any tests you want on it such as checking forbodyordivas show in the above code.