Home › Forums › JavaScript › Get Text of a element › Re: Get Text of a element
May 2, 2012 at 1:27 pm
#102156
Mottie
Member
Try this instead… it’s more direct (demo)
this.parentNode.parentNode.getElementsByTagName('span')[0].title
The problem with the code above is that the first child node isn’t the span, it’s a text node from the tab to format the HTML. So changing that to
this.parentNode.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.childNodes[1].title
would also work, but it’s much more rigid in that if you change the number of table cells it will break.