document.querySelectorAll returns values only after inspecting DOMs
Trying to get these 2 elements having the same class with "document.querySelectorAll(".sc-gHboQg"), but it returns and empty NodeList:
As soon as I inspect the element:
only now I can get them:
As far as I understand these elements are outputted dynamically in javascript, probably react, but how can I get them without having to inspect them first?
javascript reactjs
|
show 1 more comment
Trying to get these 2 elements having the same class with "document.querySelectorAll(".sc-gHboQg"), but it returns and empty NodeList:
As soon as I inspect the element:
only now I can get them:
As far as I understand these elements are outputted dynamically in javascript, probably react, but how can I get them without having to inspect them first?
javascript reactjs
At what time are you getting the elements? are you waiting for DOMContentLoaded?
– Luis Cabrera Benito
Nov 21 '18 at 18:44
Could there be another event at play, like mouseover, click, etc. triggering a class change?
– Logan Bertram
Nov 21 '18 at 18:45
It's not time related, nor at play, mouseover or click on it, I tried them all without inspecting the element in the console, but nothing..
– Alessandro Crotti
Nov 21 '18 at 18:50
I believe it's time-related. Try to get them after some time usingsetTimeout
– Dominik Krzywiecki
Nov 21 '18 at 18:57
1
stackoverflow.com/questions/28163033/…
– chrisg86
Nov 21 '18 at 19:08
|
show 1 more comment
Trying to get these 2 elements having the same class with "document.querySelectorAll(".sc-gHboQg"), but it returns and empty NodeList:
As soon as I inspect the element:
only now I can get them:
As far as I understand these elements are outputted dynamically in javascript, probably react, but how can I get them without having to inspect them first?
javascript reactjs
Trying to get these 2 elements having the same class with "document.querySelectorAll(".sc-gHboQg"), but it returns and empty NodeList:
As soon as I inspect the element:
only now I can get them:
As far as I understand these elements are outputted dynamically in javascript, probably react, but how can I get them without having to inspect them first?
javascript reactjs
javascript reactjs
edited Nov 21 '18 at 18:44
chazsolo
5,3901233
5,3901233
asked Nov 21 '18 at 18:43
Alessandro CrottiAlessandro Crotti
728
728
At what time are you getting the elements? are you waiting for DOMContentLoaded?
– Luis Cabrera Benito
Nov 21 '18 at 18:44
Could there be another event at play, like mouseover, click, etc. triggering a class change?
– Logan Bertram
Nov 21 '18 at 18:45
It's not time related, nor at play, mouseover or click on it, I tried them all without inspecting the element in the console, but nothing..
– Alessandro Crotti
Nov 21 '18 at 18:50
I believe it's time-related. Try to get them after some time usingsetTimeout
– Dominik Krzywiecki
Nov 21 '18 at 18:57
1
stackoverflow.com/questions/28163033/…
– chrisg86
Nov 21 '18 at 19:08
|
show 1 more comment
At what time are you getting the elements? are you waiting for DOMContentLoaded?
– Luis Cabrera Benito
Nov 21 '18 at 18:44
Could there be another event at play, like mouseover, click, etc. triggering a class change?
– Logan Bertram
Nov 21 '18 at 18:45
It's not time related, nor at play, mouseover or click on it, I tried them all without inspecting the element in the console, but nothing..
– Alessandro Crotti
Nov 21 '18 at 18:50
I believe it's time-related. Try to get them after some time usingsetTimeout
– Dominik Krzywiecki
Nov 21 '18 at 18:57
1
stackoverflow.com/questions/28163033/…
– chrisg86
Nov 21 '18 at 19:08
At what time are you getting the elements? are you waiting for DOMContentLoaded?
– Luis Cabrera Benito
Nov 21 '18 at 18:44
At what time are you getting the elements? are you waiting for DOMContentLoaded?
– Luis Cabrera Benito
Nov 21 '18 at 18:44
Could there be another event at play, like mouseover, click, etc. triggering a class change?
– Logan Bertram
Nov 21 '18 at 18:45
Could there be another event at play, like mouseover, click, etc. triggering a class change?
– Logan Bertram
Nov 21 '18 at 18:45
It's not time related, nor at play, mouseover or click on it, I tried them all without inspecting the element in the console, but nothing..
– Alessandro Crotti
Nov 21 '18 at 18:50
It's not time related, nor at play, mouseover or click on it, I tried them all without inspecting the element in the console, but nothing..
– Alessandro Crotti
Nov 21 '18 at 18:50
I believe it's time-related. Try to get them after some time using
setTimeout
– Dominik Krzywiecki
Nov 21 '18 at 18:57
I believe it's time-related. Try to get them after some time using
setTimeout
– Dominik Krzywiecki
Nov 21 '18 at 18:57
1
1
stackoverflow.com/questions/28163033/…
– chrisg86
Nov 21 '18 at 19:08
stackoverflow.com/questions/28163033/…
– chrisg86
Nov 21 '18 at 19:08
|
show 1 more comment
1 Answer
1
active
oldest
votes
It is due to the javascript console changed scope after you inspect element. Notice how top
in the first image changed to something else(mews...
) in the second image.
Your target element is probably in an iframe, or something that is not in a same javascript console scope than the top window?
I see, I didn't notice that. It's not an iframe though, I just checked the page source and no iframes at all. Besides, do you know how can I overcome this?
– Alessandro Crotti
Nov 21 '18 at 19:16
Try clicking on thetop
, and see what causes the scope change in the list? For me it is usually eitheriframe
orextension
– William Chong
Nov 21 '18 at 19:18
You were right, in fact there is an iframe, I just didn't see it. Thanks much for your help.
– Alessandro Crotti
Nov 21 '18 at 20:16
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418650%2fdocument-queryselectorall-returns-values-only-after-inspecting-doms%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It is due to the javascript console changed scope after you inspect element. Notice how top
in the first image changed to something else(mews...
) in the second image.
Your target element is probably in an iframe, or something that is not in a same javascript console scope than the top window?
I see, I didn't notice that. It's not an iframe though, I just checked the page source and no iframes at all. Besides, do you know how can I overcome this?
– Alessandro Crotti
Nov 21 '18 at 19:16
Try clicking on thetop
, and see what causes the scope change in the list? For me it is usually eitheriframe
orextension
– William Chong
Nov 21 '18 at 19:18
You were right, in fact there is an iframe, I just didn't see it. Thanks much for your help.
– Alessandro Crotti
Nov 21 '18 at 20:16
add a comment |
It is due to the javascript console changed scope after you inspect element. Notice how top
in the first image changed to something else(mews...
) in the second image.
Your target element is probably in an iframe, or something that is not in a same javascript console scope than the top window?
I see, I didn't notice that. It's not an iframe though, I just checked the page source and no iframes at all. Besides, do you know how can I overcome this?
– Alessandro Crotti
Nov 21 '18 at 19:16
Try clicking on thetop
, and see what causes the scope change in the list? For me it is usually eitheriframe
orextension
– William Chong
Nov 21 '18 at 19:18
You were right, in fact there is an iframe, I just didn't see it. Thanks much for your help.
– Alessandro Crotti
Nov 21 '18 at 20:16
add a comment |
It is due to the javascript console changed scope after you inspect element. Notice how top
in the first image changed to something else(mews...
) in the second image.
Your target element is probably in an iframe, or something that is not in a same javascript console scope than the top window?
It is due to the javascript console changed scope after you inspect element. Notice how top
in the first image changed to something else(mews...
) in the second image.
Your target element is probably in an iframe, or something that is not in a same javascript console scope than the top window?
answered Nov 21 '18 at 19:11
William ChongWilliam Chong
939416
939416
I see, I didn't notice that. It's not an iframe though, I just checked the page source and no iframes at all. Besides, do you know how can I overcome this?
– Alessandro Crotti
Nov 21 '18 at 19:16
Try clicking on thetop
, and see what causes the scope change in the list? For me it is usually eitheriframe
orextension
– William Chong
Nov 21 '18 at 19:18
You were right, in fact there is an iframe, I just didn't see it. Thanks much for your help.
– Alessandro Crotti
Nov 21 '18 at 20:16
add a comment |
I see, I didn't notice that. It's not an iframe though, I just checked the page source and no iframes at all. Besides, do you know how can I overcome this?
– Alessandro Crotti
Nov 21 '18 at 19:16
Try clicking on thetop
, and see what causes the scope change in the list? For me it is usually eitheriframe
orextension
– William Chong
Nov 21 '18 at 19:18
You were right, in fact there is an iframe, I just didn't see it. Thanks much for your help.
– Alessandro Crotti
Nov 21 '18 at 20:16
I see, I didn't notice that. It's not an iframe though, I just checked the page source and no iframes at all. Besides, do you know how can I overcome this?
– Alessandro Crotti
Nov 21 '18 at 19:16
I see, I didn't notice that. It's not an iframe though, I just checked the page source and no iframes at all. Besides, do you know how can I overcome this?
– Alessandro Crotti
Nov 21 '18 at 19:16
Try clicking on the
top
, and see what causes the scope change in the list? For me it is usually either iframe
or extension
– William Chong
Nov 21 '18 at 19:18
Try clicking on the
top
, and see what causes the scope change in the list? For me it is usually either iframe
or extension
– William Chong
Nov 21 '18 at 19:18
You were right, in fact there is an iframe, I just didn't see it. Thanks much for your help.
– Alessandro Crotti
Nov 21 '18 at 20:16
You were right, in fact there is an iframe, I just didn't see it. Thanks much for your help.
– Alessandro Crotti
Nov 21 '18 at 20:16
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53418650%2fdocument-queryselectorall-returns-values-only-after-inspecting-doms%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
At what time are you getting the elements? are you waiting for DOMContentLoaded?
– Luis Cabrera Benito
Nov 21 '18 at 18:44
Could there be another event at play, like mouseover, click, etc. triggering a class change?
– Logan Bertram
Nov 21 '18 at 18:45
It's not time related, nor at play, mouseover or click on it, I tried them all without inspecting the element in the console, but nothing..
– Alessandro Crotti
Nov 21 '18 at 18:50
I believe it's time-related. Try to get them after some time using
setTimeout
– Dominik Krzywiecki
Nov 21 '18 at 18:57
1
stackoverflow.com/questions/28163033/…
– chrisg86
Nov 21 '18 at 19:08