Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  148] [ 7]  / answers: 1 / hits: 20613  / 11 Years ago, fri, april 19, 2013, 12:00:00

I am trying to get the innerHTML of a hidden span. The JavaScript is from an iframe HTML page, and the hidden span resides in the parent page. A different function works when accessing contents of a list from the parent, but I can't seem to get at my span...



WORKS



document.getElementById(parent.genL[i]);


DOESNT WORK



document.getElementById(parent.span+i).innerHTML;
- SyntaxError: missing name after . operator


The above line of code resides in a for loop and as it iterates through i it will grab data from each separate span. the hidden spans start at ID span1 through upwards of 10-40k different hidden spans.



Anyways, I have a feeling that it has to do something with trying to concatenate the string int i. I assume i is an int anyways. Any thoughts? Thanks so much everyone!



Edit - Words, and added the innerHTML portion to the doesn't work line of code. Not sure if that will be making a difference or not...



Edit2 - Great answers everyone, learned some good syntactical tricks :) I simply moved the parent. portion to the front of the code as reccomend by the comment of mplungjan and the answer from Jacob T. Nielson. For some reason I still got the error using the brackets as suggested, but I will definitely tuck the brackets into my memory for future similar situations!



parent.document.getElementById(span+i).innerHTML;


:)


More From » javascript

 Answers
25

I think what you are trying to do is get the i-th span element on the parent page. Correct?



You can do it like this



var s = parent.document.getElementsByTagName('span')[i];
s.innerHTML // <-- access innerHTML

[#78776] Thursday, April 18, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
karleel

Total Points: 309
Total Questions: 79
Total Answers: 86

Location: Monaco
Member since Sun, Jan 16, 2022
2 Years ago
;