Is it possible to check if an element exists in jQuery using the length function, even though the element is empty?
I have an empty div <div id="myDiv"></div> that gets populated by AJAX when the user scrolls to a certain point on the screen, but when I try targeting the div before that point I'm getting nothing. The code I'm using is…
if( jQuery('#myDiv').length) {
alert('#myDiv exists!');
} else {
alert('#myDiv doesn\'t exist!');
}
but I'm wondering if the reason it isn't selecting the div is because it's empty. Does that matter when using the length function?
.lengthis a property not a function!