Jump to content

Getelementsbytagname On Firefox


joecool2005
 Share

Recommended Posts

Hi,Why my alert does not work on Firefox but it works on IE?Thanks for your help

<html><head><script type="text/javascript">function getElements(){var x=document.getElementsByTagName("input");alert(x(0).name);}</script></head><body><input name="myInput" type="text" size="20" /><br /><input name="myInput" type="text" size="20" /><br /><input name="myInput" type="text" size="20" /><br /><br /><input type="button" onclick="getElements()" value="How many input elements?" /></body></html>

Link to comment
Share on other sites

Hi,Why my alert does not work on Firefox but it works on IE?Thanks for your help
<html><head><script type="text/javascript">function getElements(){var x=document.getElementsByTagName("input");alert(x(0).name);}</script></head><body><input name="myInput" type="text" size="20" /><br /><input name="myInput" type="text" size="20" /><br /><input name="myInput" type="text" size="20" /><br /><br /><input type="button" onclick="getElements()" value="How many input elements?" /></body></html>

This line is wrong:
alert(x(0).name);

Use either:

alert(x[0].name);

or

alert(x.item(0).name);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...