My guess (since you've shown no html) is that you have some white space (perhaps a line break) which IE is ignoring, but which FF is returning as a text node. If so, you should be able to skip over it with something like:
function PopupTest() {
var hdnButton = document.getElementById('div_btn').firstChild;
while (hdnButton.nodeType === 3)
hdnButton = hdnButton.nextSibling;
hdnButton.click();
}
...which works by using the .nodeType
property to test whether the .firstChild
is a text node (3
means text node; for more information see MDN). If it is, it takes the next sibling and tests its .nodeType
, and so on until it finds an element that isn't a text node. (Of course this assumes there will be one.)
Alternatively if you know what tag the (non text node) first child should be you could select it on that basis, e.g., if it's actually a <button>
element:
hdnButton = document.getElementById('div_btn').getElementsByTagName("button")[0];
hdnButton.click();
Or if you don't need to support IE<=7:
document.querySelector("#div_btn > :first-child").click();