Why do i get a [Text Object] instead of the expected TR object with previousSibling in javascript? -
so if have html code this:
<html> <head> <title>this test</title> </head> <body> <table> <tr> <td>first cell</td> </tr> <tr> <td>second cell</td> <td><a href="#" onclick="alert(this.parentnode.parentnode.previoussibling.childnodes[0].innerhtml); return false;">click here</a></td> </tr> </table> </body> </html>
this works internet explorer, not firefox , more browsers out there. apparently firefox interprets whitespace between tr's(indentation) previoussibling of parent tr of 'this' in code above. instead of getting desired tr object gives me [text object].
so question is, why doesn't firefox ignore whitespace between tr's internet explorer does. know can use previouselementsibling circumvent this, want know why firefox , if there logical explanation or use it. i've tried looking on internet no avail. if tell me or give me link can find information, appreciate it!
yes correct. ie principally wrong. here mozilla's take on it
you can
a) use parentnode.getelementsbytagname
b) flatten dom looping loop until nodetype looking for: here simpler script mozilla gave in link above: http://blog.tegneblokken.net/2009/08/counting-childnodes-with-javascript-the-whitespace-incident/
c) use jquery
Comments
Post a Comment