Jump to content

Getelementsbytagname On Firefox


joecool2005

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...