admin管理员组文章数量:1419640
Firefox returns null when I try to call document.getElementById on an element.
Here is the call
document.getElementById('interaction4793')
However the element is present in the DOM. I can find it
<interaction id="interaction4793">
<action id="action3268" trigger="enter" type="hover" />
<reaction delay="0" id="reaction3709" options="reloadOnly" target="page0001" transition="none" type="showPage" />
</interaction>
Even when I select it from the inspector and use the $0 trick it returns null:
document.getElementById($0.id)
When I try to get the elements from getElementsById it works.
EDIT: Chrome and Safari do not return null. I tested Firefox (version 26) on Window and MacOS both return null.
EDIT2:
I think Firefox do not understand that the attribute id
is the id. When I search by attribute with jquery I can find the interaction:
console.log($('#interaction102').length); // returns 0
console.log($('[id="interaction102"]').length); // returns 1
Firefox returns null when I try to call document.getElementById on an element.
Here is the call
document.getElementById('interaction4793')
However the element is present in the DOM. I can find it
<interaction id="interaction4793">
<action id="action3268" trigger="enter" type="hover" />
<reaction delay="0" id="reaction3709" options="reloadOnly" target="page0001" transition="none" type="showPage" />
</interaction>
Even when I select it from the inspector and use the $0 trick it returns null:
document.getElementById($0.id)
When I try to get the elements from getElementsById it works.
EDIT: Chrome and Safari do not return null. I tested Firefox (version 26) on Window and MacOS both return null.
EDIT2:
I think Firefox do not understand that the attribute id
is the id. When I search by attribute with jquery I can find the interaction:
console.log($('#interaction102').length); // returns 0
console.log($('[id="interaction102"]').length); // returns 1
Share
Improve this question
edited Jan 17, 2014 at 16:24
Charles
asked Jan 17, 2014 at 13:28
CharlesCharles
11.8k10 gold badges81 silver badges122 bronze badges
6
-
5
When do you call
document.getElementById('interaction4793')
? – CodingIntrigue Commented Jan 17, 2014 at 13:30 - 2 Works for me with Firefox – Andy Commented Jan 17, 2014 at 13:30
- Yes it's strange, it works for me too on a blank page. When I try it in my webapp, it returns always null... – Charles Commented Jan 17, 2014 at 13:32
- I call it during the use of the webapp. The DOM is already ready and the element is there. – Charles Commented Jan 17, 2014 at 13:33
-
1
Are you sure you don't have another tag with the same
id
? – Elliott Frisch Commented Jan 17, 2014 at 13:51
1 Answer
Reset to default 1The question is already answered here: JavaScript getElementByID() not working
Sometimes happen when the content of your website is not already loaded and crash.
Hope to be helpful
EDIT1: You can also try this: var yourvar= $("#interaction4793")[0]; It works for me
本文标签: javascriptdocumentgetElementById does not work on FirefoxStack Overflow
版权声明:本文标题:javascript - document.getElementById does not work on Firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745312400a2652994.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论