Web Analytics Made Easy -
StatCounter Node emptier - CodingForum


No announcement yet.

Node emptier

  • Filter
  • Time
  • Show
Clear All
new posts

  • Node emptier

    From a different challenge involving time-sensitive text, I came up with this little goodie.

    function clearNode (node) {
        while (node.childNodes.length > 0) {
        return node;
    I'd like to make this a method of the Node prototype, but I haven't figured out *quite* how to do it yet. Comments? Improvements?

  • #2
    Didn't normalise have the irritating property that it crashes some version of ie? I think I remember something like htat happening. Anyway, the Node object is only exhibited by Opera and Mozilla for the moment, so you'de not going to find a way to do that. Make it a global function instead.
    liorean <[[email protected]]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards


    • #3
      Are you looking to remove useless whitespace text nodes from a node tree? Cos Alex Vincent wrote a nifty method for that - http://www.codingforum.net/showthrea...&threadid=7028

      Except don't let it run in mac/ie5, because in that browser HTML structures become unstable when stripped of whitespace.
      "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark