Check if element does not exist
I'm trying to check if an element doesn't exist & if it doesn't then hide a parent:
- $('#imagepackwrapper div[id^="packimgdiv"] img.imageStyle').each(function(i) {
- var ick = $(this).length;
- console.log('Exists: ' + ick);
- if ($(this).length == 0) {
- $(this).closest('div[id^="packimgdiv"]').hide();
- }
- });
The console is only detecting those with a length of 1.
How do I detect when the image is not in dom?
HTML:
- <div id="imagepackwrapper">
- <div id="packimgdiv0">
- <div>
- <img class="imageStyle" > // sometimes this image will be missing from dom
- </div>
- </div>
- ... other packimgdiv's
- </div>