My goal is to check if an element exists, but not just that, the element is.. well let me show you: if(document.getElementsByClassName("outerBox").getElementsByClassName("innerBox")) {//some code}
. Now the problem is that if outerBox
doesnt exist, it gives me this error message in the console: Uncaught TypeError: Cannot read property 'getElementsByClassName' of undefined
.
I do not care weather the outerBox
exists if it doesn't have the innerBox
as a child, and also I do not care if the innerBox
exsists outside of the outerBox
. They have to be child and parent to eachother.
The code works, but I would like to get rid of the error, for a cleaner expirience, and because it isn't a good practise to leave errors displaying around like that, specially because you can't really use the console while this error is going, because the code is run every 100 milliseconds, so it just spams the console like crazy.
- Now jsut one last thing, I can't use any outside library like jQuery, only vanilla Javascript.