Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Node emptier

  1. #1
    Regular Coder
    Join Date
    Apr 2003
    Location
    Atlanta, GA
    Posts
    487
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Node emptier

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

    Code:
    function clearNode (node) {
        node.normalize();
        while (node.childNodes.length > 0) {
            node.removeChild(node.firstChild);
        }
        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
    Master Coder
    Join Date
    Feb 2003
    Location
    UmeŚ, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    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 <[lio@wg]>
    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
    Senior Coder
    Join Date
    Jun 2002
    Location
    near Oswestry
    Posts
    4,508
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you looking to remove useless whitespace text nodes from a node tree? Cos Alex Vincent wrote a nifty method for that - Cleaning useless whitespace in Mozilla DOM

    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •