document.querySelectorAll returns values only after inspecting DOMs












3















Trying to get these 2 elements having the same class with "document.querySelectorAll(".sc-gHboQg"), but it returns and empty NodeList:



enter image description here



As soon as I inspect the element:
enter image description here



only now I can get them:
enter image description here



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?










share|improve this question

























  • 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
















3















Trying to get these 2 elements having the same class with "document.querySelectorAll(".sc-gHboQg"), but it returns and empty NodeList:



enter image description here



As soon as I inspect the element:
enter image description here



only now I can get them:
enter image description here



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?










share|improve this question

























  • 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














3












3








3








Trying to get these 2 elements having the same class with "document.querySelectorAll(".sc-gHboQg"), but it returns and empty NodeList:



enter image description here



As soon as I inspect the element:
enter image description here



only now I can get them:
enter image description here



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?










share|improve this question
















Trying to get these 2 elements having the same class with "document.querySelectorAll(".sc-gHboQg"), but it returns and empty NodeList:



enter image description here



As soon as I inspect the element:
enter image description here



only now I can get them:
enter image description here



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 using setTimeout

    – 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











  • 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

















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












1 Answer
1






active

oldest

votes


















1














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?






share|improve this answer
























  • 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











  • 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











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
});


}
});














draft saved

draft discarded


















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









1














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?






share|improve this answer
























  • 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











  • 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
















1














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?






share|improve this answer
























  • 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











  • 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














1












1








1







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?






share|improve this answer













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?







share|improve this answer












share|improve this answer



share|improve this answer










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 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



















  • 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











  • 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




















draft saved

draft discarded




















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini