Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. how do I remove a node?

how do I remove a node?

Scheduled Pinned Locked Moved Web Development
htmlquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    theJazzyBrain
    wrote on last edited by
    #1

    I am using the DOM along with DHTML to dynamically manipulate html... According to a certain event I need to remove a node, but I cant find a method for removing or deleting nodes. I am aware of the replaceNode() method but this requires another node to replace the old one with which is not good for me... Any ideas?:confused: Thank you |---------------| | theJazzyBrain  | |---------------|

    A 1 Reply Last reply
    0
    • T theJazzyBrain

      I am using the DOM along with DHTML to dynamically manipulate html... According to a certain event I need to remove a node, but I cant find a method for removing or deleting nodes. I am aware of the replaceNode() method but this requires another node to replace the old one with which is not good for me... Any ideas?:confused: Thank you |---------------| | theJazzyBrain  | |---------------|

      A Offline
      A Offline
      Anonymous
      wrote on last edited by
      #2

      Using DHTML, you can always parse out the HTML tag of the element you wish to delete from the parent's innerHTML and set it back. EX:

      function DeleteElement(oElem) {
      var oParent = oElem.parentElement;
      var cParentHTML = StringReplace(oParent.innerHTML,"\r\n","");
      var cDeleteHTML = StringReplace(oElem.outerHTML,"\r\n","");

      var iIndex = cParentHTML.indexOf(cDeleteHTML);
      if (iIndex > -1)
      {
      oParent.innerHTML = cParentHTML.substr(0,iIndex) + cParentHTML.substr(iIndex+cDeleteHTML.length);
      }

      }

      function StringReplace(cSearch, cFind, cReplace) {
      var iPos = cSearch.indexOf(cFind);
      while (iPos > -1)
      {
      cSearch = cSearch.substr(0,iPos) + cReplace + cSearch.substr(iPos+cFind.length);
      iPos = cSearch.indexOf(cFind);
      }

      return cSearch;
      }

      Hope this helps (and i just typed this in, so don't rely on it working).

      B B 2 Replies Last reply
      0
      • A Anonymous

        Using DHTML, you can always parse out the HTML tag of the element you wish to delete from the parent's innerHTML and set it back. EX:

        function DeleteElement(oElem) {
        var oParent = oElem.parentElement;
        var cParentHTML = StringReplace(oParent.innerHTML,"\r\n","");
        var cDeleteHTML = StringReplace(oElem.outerHTML,"\r\n","");

        var iIndex = cParentHTML.indexOf(cDeleteHTML);
        if (iIndex > -1)
        {
        oParent.innerHTML = cParentHTML.substr(0,iIndex) + cParentHTML.substr(iIndex+cDeleteHTML.length);
        }

        }

        function StringReplace(cSearch, cFind, cReplace) {
        var iPos = cSearch.indexOf(cFind);
        while (iPos > -1)
        {
        cSearch = cSearch.substr(0,iPos) + cReplace + cSearch.substr(iPos+cFind.length);
        iPos = cSearch.indexOf(cFind);
        }

        return cSearch;
        }

        Hope this helps (and i just typed this in, so don't rely on it working).

        B Offline
        B Offline
        basementman
        wrote on last edited by
        #3

        Sorry, forgot to sign in before posting...;P  onwards and upwards...

        1 Reply Last reply
        0
        • A Anonymous

          Using DHTML, you can always parse out the HTML tag of the element you wish to delete from the parent's innerHTML and set it back. EX:

          function DeleteElement(oElem) {
          var oParent = oElem.parentElement;
          var cParentHTML = StringReplace(oParent.innerHTML,"\r\n","");
          var cDeleteHTML = StringReplace(oElem.outerHTML,"\r\n","");

          var iIndex = cParentHTML.indexOf(cDeleteHTML);
          if (iIndex > -1)
          {
          oParent.innerHTML = cParentHTML.substr(0,iIndex) + cParentHTML.substr(iIndex+cDeleteHTML.length);
          }

          }

          function StringReplace(cSearch, cFind, cReplace) {
          var iPos = cSearch.indexOf(cFind);
          while (iPos > -1)
          {
          cSearch = cSearch.substr(0,iPos) + cReplace + cSearch.substr(iPos+cFind.length);
          iPos = cSearch.indexOf(cFind);
          }

          return cSearch;
          }

          Hope this helps (and i just typed this in, so don't rely on it working).

          B Offline
          B Offline
          Bjoern Graf
          wrote on last edited by
          #4

          Kinda expensive solution :) DOM1 defines the removeChild method, so why not use it:

          var parent = document.getElementById("anelement");
          var child = document.getElementById("anotherelement");
          parent.removeChild(child);

          IE DOM0 implements the removeNode method:

          var child = document.getElementById("anotherelement");
          child.removeNode(true);

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups