469,276 Members | 1,687 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,276 developers. It's quick & easy.

Event handler problem in FF

127 100+
I'm just getting back in to Javascript, and find the following code works fine in IE, but not in FF. For my edification, could someone please explain why?

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  4. <title>Column Content</title>
  5. <script language="javascript">
  6. function meClick(id){
  7. alert(document.getElementById(id).innerText);
  8.  
  9. }
  10. </script>
  11. </head>
  12.  
  13. <body>
  14. <table width="37%" border="0" cellpadding="0" cellspacing="0">
  15. <tr>
  16. <td width="30%" id = "c1" onClick="meClick(this.id)"><div align="center">C1</div></td>
  17. <td width="22%" id = "c2" onClick="meClick(this.id)"><div align="center">C2</div></td>
  18. <td width="48%" id = "c3" onClick="meClick(this.id)"><div align="center">C3</div></td>
  19. </tr>
  20. </table>
  21. </body>
  22. </html> 
  23.  
Thanks!
Apr 4 '09 #1
5 1044
acoder
16,027 Expert Mod 8TB
Try textContent in Firefox.
Apr 4 '09 #2
dmjpro
2,476 2GB
"TD" would have "innerText"? I think this is not a Text Node then how it works in IE? Please explain!
Apr 6 '09 #3
Dormilich
8,651 Expert Mod 8TB
slightly off-topic, but you can improve your function by
Expand|Select|Wrap|Line Numbers
  1. function meClick()
  2. {
  3.     alert(this.innerHTML); // this.innerText / this.textContent
  4. }
Apr 6 '09 #4
acoder
16,027 Expert Mod 8TB
@dmjpro
See an explanation of innerText.
Apr 6 '09 #5
phub11
127 100+
Thanks for all the replies... I'm actually doing things in a slightly different way now. Please see my more recent posts if you are interested.

Thanks again!
Apr 6 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by tony kulik | last post: by
18 posts views Thread by Christopher W. Douglas | last post: by
8 posts views Thread by Mark | last post: by
6 posts views Thread by vbMark | last post: by
13 posts views Thread by Charles Law | last post: by
3 posts views Thread by Beth | last post: by
5 posts views Thread by Richard Grant | last post: by
2 posts views Thread by John Kotuby | last post: by
2 posts views Thread by =?Utf-8?B?UlJK?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.