javascript - Getting the script tag using getElementsByTagName inconsistent across browsers -


i have following code:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script> <script>     $(document).ready(function(){         var script_obj = document.getelementsbytagname('script')         alert(typeof script_obj);     }); </script> 

when run in firefox (v21) , chrome (v29) object result, in safari (v5) function.

why this?!

in rest of script i'm iterating through script_obj .src data, count function determines length of haystack (i.e. script_obj) has check returns false if haystack not array or object, failing in safari. there way can instead of using document.getelementsbytagname('script')?!

document.getelementsbytagname() returns nodelist. although nodelist not array, have length property array. don't need special count number of items in it. not sure count function doing, can this:

> var script_obj = document.getelementsbytagname('script'); > alert(script_obj.length); // alert '22' or whatever 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -