0

I am working on a javascript downloader and need to click a button. I can see the button and get it's values with web developer and dom inspector in FF. But when I try to:

var freeUserForm = this.iFrame.contentDocument.getElementById('js_free-download_btn');

It returns null and when I view the page source the element is not there. So what's going on?

Thank you very much, Todd

maddogandnoriko
  • 980
  • 2
  • 13
  • 31
  • We'll need to see the rest of the code to be sure that your id's and component hierarchy is correct. – Jivings Sep 29 '10 at 16:24
  • The way that the `this` keyword works in JavaScript is a little weird. Maybe add a trace statement to make sure that it's referring to the object you think it's referring to. – Tyler Sep 29 '10 at 16:51
  • I turns out the page was loading 3 pages via refreshes and when I was trying to get the element the third DOM had not loaded yet. – maddogandnoriko Oct 06 '10 at 14:34

1 Answers1

1

(assuming that the ID of the IFRAME element is "foo")

var iframe = document.getElementById("foo");
var freeUserForm = iframe.contentDocument.getElementById("js_free-download_btn");
Šime Vidas
  • 182,163
  • 62
  • 281
  • 385