My question is pretty much the same as JavaScript, elegant way to check nested object properties for NULL/undefined
however instead of dot notation in dictionaries I need to be able to do the same with dom for example:
div[0].children[1].children[0].children[1]
Now what I COULD do is
if(div[0] && div[0].children[1] && div[0].children[1].children[0]...
but this would make my code blow up. I've tried to use the top voted answer in the linked question but this didn't work once I added the .children in there, it would simply throw false every time. Trying to access it via try/catch does work for the divs that do contain those entries.
Using lodash's get works safely but I don't want to deploy 6kb of this module for something that might get achieved otherwise.
div>:nth-child(2)>:nth-child(1)>:nth-child(2)?divOb = document.getElementsByClassName(' js-gps-track nav-links--link')[0]; document.querySelector("[data-name=" + divOb + "]");<element>.querySelectorrather thandocument.querySelector(and use.querySelectorAllif multiple element matches is a possibility)