I try to get element which id is "div", but I get an TypeofError in firefox, what's the reason?
<script type="text/javascript">
window.onload = function (){
var oParent = document.getElementsByTagName('div')[0];
console.log(oParent);
var arr = oParent.getElementById('div');
console.log(arr);
}
</script>
<div class="test">
<div></div>
<div></div>
<div id="div"></div>
<div></div>
You should replace
var arr = oParent.getElementById('div');
with
var arr = document.getElementById('div');
This because getElementById
is a method of document
and not of the divs.
It doesn't work because you use the method "getElementById" from oParent object. But this method is available from document object.
var arr = document.getElementById('div');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With