+ 1
Scope of DOM
Giving commands via console in Chrome, the value of x= document.body.getElementByTag("span") sometimes returns the all span elements of the actual html, othertimes returns the all span elements inside of a iframe in the actual html. How to control the scope of DOM?
10 Respuestas
+ 7
I'm not too sure whether this will work with the spans in the iframe, but perhaps you can try:
x = document.querySelectorAll("body span") for all the spans within body scope.
x = document.querySelectorAll("#container span") for all the spans within scope of a container having Id #container.
x = document.querySelectorAll(".container span") for all the spans within scope of container(s) having class .container.
Reference:
https://www.w3schools.com/jsref/met_document_queryselectorall.asp
Hth, cmiiw
+ 4
Well, if you try on an iframe which loads a different document from other domain I suppose it should happen (wild guess). Post back here if you find a way to do it cross domain will you?
+ 3
say me if it does work
("Span[0]") indicates first span in Dom like wise 1,2,3...
+ 1
Can you put your codes here for examining?
+ 1
I think you can add an id to the span you want to do something, and use
document.getElementById
to get the span element DOM
+ 1
Welcome, though from your answer I think I have not helped you.
About how to post your problem codes
I think you can post copy of your codes
So when the x is in its case 1, you save a copy to freeze the status
Then when x is in case 2, you save another copy
Then post both codes here.
+ 1
I got problems because Cross-Domain prohibition. Anyway, was a good try
+ 1
but...I have really edited the page inside the iframe of another domain. ( I have a picture to prove it lolol). I will give you the news. Thank you again!
0
in fact, I don't know how to change the scope to do test and give you a answer. But the x value defined above changes as I atempt to get and change values inside the iframe
0
I want to get it by its html/innertext... But I need to get him first inside the iframe... to me this is very "fuzzy"... anyway, thank you for your helping