Event handler problem in FF

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phub11
    New Member
    • Feb 2008
    • 127

    Event handler problem in FF

    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?

    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Column Content</title>
    <script language="javascript">
    function meClick(id){
    alert(document.getElementById(id).innerText);
    
    }
    </script>
    </head>
    
    <body>
    <table width="37%" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="30%" id = "c1" onClick="meClick(this.id)"><div align="center">C1</div></td>
    <td width="22%" id = "c2" onClick="meClick(this.id)"><div align="center">C2</div></td>
    <td width="48%" id = "c3" onClick="meClick(this.id)"><div align="center">C3</div></td>
    </tr>
    </table>
    </body>
    </html>
    Thanks!
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Try textContent in Firefox.

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      "TD" would have "innerText" ? I think this is not a Text Node then how it works in IE? Please explain!

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        slightly off-topic, but you can improve your function by
        Code:
        function meClick()
        {
            alert(this.innerHTML); // this.innerText / this.textContent
        }

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          Originally posted by dmjpro
          "TD" would have "innerText" ? I think this is not a Text Node then how it works in IE? Please explain!
          See an explanation of innerText.

          Comment

          • phub11
            New Member
            • Feb 2008
            • 127

            #6
            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!

            Comment

            Working...