[mochikit] Re: Walk child nodes of an element
Would something like this work? function recursiveDigForText(someElement){ if(someElement.firstChild.tagName) return someElement.innerHTML; else return recursiveDigForText(someElement.firstChild); } On Dec 10, 7:53 am, JS [EMAIL PROTECTED] wrote: Hi: I'm quite new to MochiKit and javascript in general. For some reason, I can't figure out how to walk the child nodes of an element. I'm using version 1.3.1 of MochiKit with TurboGears. I have table cell and am trying to drill down into the cell to get at the text that is being displayed in it. The cell could have some SPAN elements and then either text or a link. In effect, I would like to do the following: ... while cell.hasChildren() { cell = cell.firstChild; } I realize that each cell could have multiple children, but in my specific case, it won't. I'd really appreciate any pointers to examples or good documentation. Thanks -Jim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: Walk child nodes of an element
To what end do you want to get at the text? If you simply want to grab it, use scrapeText()... Jason -Original Message- From: mochikit@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of JS Sent: Monday, December 10, 2007 8:53 AM To: MochiKit Subject: [mochikit] Walk child nodes of an element Hi: I'm quite new to MochiKit and javascript in general. For some reason, I can't figure out how to walk the child nodes of an element. I'm using version 1.3.1 of MochiKit with TurboGears. I have table cell and am trying to drill down into the cell to get at the text that is being displayed in it. The cell could have some SPAN elements and then either text or a link. In effect, I would like to do the following: ... while cell.hasChildren() { cell = cell.firstChild; } I realize that each cell could have multiple children, but in my specific case, it won't. I'd really appreciate any pointers to examples or good documentation. Thanks -Jim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---
[mochikit] Re: Walk child nodes of an element
Jason: Thanks for the tip. scrapeText did exactly what I was looking for. Machineghost, thanks for your input as well. I was working out the details of that implementation, but thought the scrapeText was a cleaner way for me to handle it. -Jim On Dec 10, 12:32 pm, Jason Bunting [EMAIL PROTECTED] wrote: To what end do you want to get at the text? If you simply want to grab it, use scrapeText()... Jason -Original Message- From: mochikit@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of JS Sent: Monday, December 10, 2007 8:53 AM To: MochiKit Subject: [mochikit] Walk child nodes of an element Hi: I'm quite new to MochiKit and javascript in general. For some reason, I can't figure out how to walk the child nodes of an element. I'm using version 1.3.1 of MochiKit with TurboGears. I have table cell and am trying to drill down into the cell to get at the text that is being displayed in it. The cell could have some SPAN elements and then either text or a link. In effect, I would like to do the following: ... while cell.hasChildren() { cell = cell.firstChild; } I realize that each cell could have multiple children, but in my specific case, it won't. I'd really appreciate any pointers to examples or good documentation. Thanks -Jim --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups MochiKit group. To post to this group, send email to mochikit@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/mochikit?hl=en -~--~~~~--~~--~--~---