Removing a element (DOM/JS)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jam Pa

    Removing a element (DOM/JS)

    Ok I am one of those unfortunate souls who have to make a text editor for
    CMS.

    So, I need to remove a <textarea> on a page (this is for non javascript
    browsers).

    I can figure out the element (getLelementByI d), but so far have been unable
    to remove it. I tried to set the elements innerHTML to "". Interestingly,
    in firefox the element is doubled (1.0.4).

    anyone have any help with this. I have ie support to work on too, so *any*
    pointers for *any* browsers on replacing elements with javascript are very
    very welcome.

  • Martin Honnen

    #2
    Re: Removing a element (DOM/JS)


    Jam Pa wrote:
    [color=blue]
    > So, I need to remove a <textarea> on a page (this is for non javascript
    > browsers).
    >
    > I can figure out the element (getLelementByI d), but so far have been unable
    > to remove it.[/color]

    if (element.parent Node && element.parentN ode.removeChild ) {
    element.parentN ode.removeChild (element);
    }

    --

    Martin Honnen

    Comment

    • Jam Pa

      #3
      Re: Removing a element (DOM/JS)

      Martin Honnen <mahotrash@yaho o.de> wrote in
      news:4295fcef$0 $25684$9b4e6d93 @newsread2.arco r-online.net:
      [color=blue]
      >
      > Jam Pa wrote:
      >[color=green]
      >> So, I need to remove a <textarea> on a page (this is for non
      >> javascript browsers).
      >>
      >> I can figure out the element (getLelementByI d), but so far have been
      >> unable to remove it.[/color]
      >
      > if (element.parent Node && element.parentN ode.removeChild ) {
      > element.parentN ode.removeChild (element);
      > }[/color]

      Thanks for your reply.

      The code below works.. at times. And sometimes it wont. Go figure...

      <div id="supa">
      <p>ldakjsdlkjas lkjsad</p>
      <p>etc</p>
      <textarea id="tarea"></textarea>
      <script language="JavaS cript" type="text/javascript">
      function removeElementBy Id() {
      parn = "supa";
      rele = "storyarea" ;
      pare = document.getEle mentById(parn);
      rele = document.getEle mentById(rele);
      fstatus = "";

      if (tarea.parentNo de && tarea.parentNod e.removeChild
      (tarea)) { tarea.parentNod e.removeChild(t area); }
      else { alert("Nada!"); }
      fstatus = "jaa";
      return fstatus;
      }
      removeElementBy Id();
      </script>
      </div>


      Comment

      • Jam Pa

        #4
        Re: Removing a element (DOM/JS)

        Ok well this is how Im working this script in 'final' (lol):

        function removeElementBy Id(remele) {
        remele = document.getEle mentById(remele );
        if (remele.parentN ode && remele.parentNo de.removeChild( remele)) {
        remele.parentNo de.removeChild( remele); }
        }

        removeElementBy Id("storyarea") ;

        I hope this may help someone out there

        Comment

        • RobG

          #5
          Re: Removing a element (DOM/JS)

          Jam Pa wrote:[color=blue]
          > Ok well this is how Im working this script in 'final' (lol):[/color]

          Please don't post code with tabs, replace them with spaces. It nearly
          always
          causes wrapping that introduces errors.
          [color=blue]
          >
          > function removeElementBy Id(remele) {
          > remele = document.getEle mentById(remele );
          > if (remele.parentN ode && remele.parentNo de.removeChild( remele)) {[/color]

          Here you will actually call the removeChild method, not just test it.
          The intention is to test the method, and if it's supported, call it:

          if ( remele.parentNo de && remele.parentNo de.removeChild ) {
          [color=blue]
          > remele.parentNo de.removeChild( remele); }
          > }[/color]


          If the method is not supported, you will get an error from the if(..),
          if the method is supported, you will get an error from this line
          because 'remele' was already removed in the test.
          [color=blue]
          >
          > removeElementBy Id("storyarea") ;
          >
          > I hope this may help someone out there[/color]

          I hope this helps you! 8-p

          --
          Rob

          Comment

          Working...