Detect if Specific Modal is displayed/visible using JavaScript

894359
894359 used Ask the Experts™
on
I'm trying to figure out if I can detect when a specific modal (see attached image) is displayed using pure JS (no jQuery). If you go to  https://www.bankofthewest.com/personal-banking/checking-accounts.html in Chrome, Incognito mode (or just clear your cookies in standard mode, you see the "State Selector" modal show. Once a State is selected and submitted the page will close the modal and refresh. Is there any way to detect if this modal is being displayed and if so, how?

Thanks!
stateSelectorExample.png
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Consultant & Challenge Subduer
Top Expert 2009
Commented:
jQuery can be very helpful, but it's not magic, so of course something that can be done with it can be done without it.

In this case it seems to be fairly simple:
if(document.getElementById('stateSelectorModal').style.display==='block')

Open in new window

Author

Commented:
Would it be any better to use something like this:

if(document.getElementById('stateSelectorModal').offsetHeight > 0)
David S.Consultant & Challenge Subduer
Top Expert 2009

Commented:
You could do that, but there is more than one way to hide an element (and checking the offsetHeight only works for some of them), so you might as well just check the one that is being used.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial