470,585 Members | 1,659 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,585 developers. It's quick & easy.

Getting NULL when trying to use queryselector to fetch dom elements

24 Expert 16bit
I keeping getting NULL when using queryselector to fetch DOMelements that have been created after the site has loaded.

Does anyone know why this happens?

The first selector clicks on the menu
The second selector clicks on the menu option that only loads and gets added to the DOM after the first is clicked

1) site loads
2) i run the following code to fetch dom elements via the web developer console
Expand|Select|Wrap|Line Numbers
  2. function fetchElement(){
  3.     document.querySelectorAll('[data-menu="menu"]')[0].click()
  4.     document.querySelectorAll('[data-option="menuitem"]')[0].click()
  5. }
  6. fetchElement()
The second click returns null.

I am wondering if it's because those menuitems get added to the DOM after the first click? So it's not actually there, but if that's the case how would I access those elements?

Thank You,
2 Weeks Ago #1
1 10857
569 Expert 512MB
Post the specific/minimum code able to reproduce the error.
2 Weeks Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by comp.lang.php | last post: by
1 post views Thread by =?Utf-8?B?QmFydA==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.