WEB Javascript DOM children / nodes / appending / removing

Discussion in 'OT Technology' started by pharmokan, Aug 2, 2009.

  1. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    simple scenario:

    Code:
    <html>
    <head>
    <script type="text/javascript"> 
    <!--
    function textIns() {
    var theText = document.createTextNode("Hello World");
    var here = document.getElementById("textBoxx")
    var parentDiv=here.parentNode
    parentDiv.appendChild(theText);
    }
    
    function clearTextAndIns() {
    textBoxx.removeNode(true);
    var theTextNew = document.createTextNode("NEW TEXT");
    var here = document.getElementById("textBoxx")
    var parentDiv=here.parentNode
    parentDiv.appendChild(theTextNew);
    
    }
    
    
    
    //-->
    </script>
    
    </head>
    <body>
    <a href="javascript:textIns()"> click here to insert text</a>  <br />
    <a href="javascript:clearTextAndIns()">click here to clear and insert new text</a>
    
    
    <div style="margin-top:200px;width:500px; border:1px solid black;padding:20px;">
    
    <p id="textBoxx"> 
    </p>
    
    </div>
    
    
    </body>
    
    </html>
    
    the clear call does not work properly. it does not remove the text node "Hello World" probably because it has been dynamically generated. does anyone know the proper way to remove dynamic generated text nodes and replace them with new text nodes?
     
  2. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    phasm is gay for viewing thread and not posting reply
     
  3. Phasm

    Phasm OT Supporter

    Joined:
    Sep 20, 2005
    Messages:
    9,680
    Likes Received:
    0
    Location:
    Michigan
    you suck dick at javascript bro
     
  4. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    i know bro i hate javascript.

    its a de facto scripting language
     
  5. Phasm

    Phasm OT Supporter

    Joined:
    Sep 20, 2005
    Messages:
    9,680
    Likes Received:
    0
    Location:
    Michigan
    :werd: I suck at it too but felt like being a dick about it
     
  6. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,918
    Likes Received:
    10
    Location:
    Los Angeles
    parentDiv.removeChild(parentDiv);
     
  7. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    Hello WorldNEW TEXT

    output. :sad2:
     
  8. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    ok so maybe i shouldnt go the route of node operators to dynamically change content within html tags

    is there a way i can put <script>var</script> within html tags and have the anchor tags change the value of var? im stuck here.

    this is why i hate javascript

    theres 300 billion ways of doing the same thing and each way has its flaws
     
  9. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    :uh: :uh: :uh:
    Code:
    function clearTextandIns() {
    document.getElementById("textBoxx").innerHTML="Hello World"
    }
    
    see what i mean

    300 fucking billion ways of doing same shit

    i dont even have to go the route of node operators to change text upon clicking anchors

    innerHTML changes it dynamically
     
  10. fishbulb

    fishbulb Active Member

    Joined:
    Oct 29, 2001
    Messages:
    6,848
    Likes Received:
    4
    Location:
    md
  11. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
  12. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    yeah i know innerHTML is an unsafe shortcut

    but my feelings toward this project:

    :dunno: NO CARE
     
  13. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    microsoft made up innerHTML model


    firefox apparently still accepts it when it parses its xhtml/xml docs

    so...im in the clear? :coold:

    :gtfo: chrome + safari

    ibhate
     
  14. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.

    from the article:

    Since it's not a standard, it isn't terribly future proof. It's not supposed to work under the application/xhtml+xml MIME type that XHTML documents are supposed to be served under. (Firefox 1.5 changed this by allowing it for some reason)

    does firefox 3.5 still allow this
     
  15. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    YOU MAD UNINFORMED SON
     
  16. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,918
    Likes Received:
    10
    Location:
    Los Angeles
    InnerHTML :rofl: Do it the right way. It won't be that much more effort. :dunno:
     
  17. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    extra 12 lines of code FTL
     
  18. kingtoad

    kingtoad OT Supporter

    Joined:
    Sep 2, 2003
    Messages:
    55,918
    Likes Received:
    10
    Location:
    Los Angeles
    If you're complaining about doing it the right way, then you should probably use a framework.

    Can be accomplished in one line of code.
     
  19. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.
    na ur right

    this project is not serious anyways. its ok i got the article i will use that as a reference for future proj
     
  20. pharmokan

    pharmokan OT Supporter

    Joined:
    Oct 18, 2002
    Messages:
    102,125
    Likes Received:
    427
    Location:
    L.A.

Share This Page