1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

can somebody please tell me wtf is this not working?

Discussion in 'HTML & JavaScript' started by Mutikasa, Aug 19, 2015.

  1. Mutikasa

    Mutikasa Power Member

    Joined:
    May 23, 2011
    Messages:
    579
    Likes Received:
    207
  2. towelfox

    towelfox Junior Member

    Joined:
    Jan 11, 2012
    Messages:
    175
    Likes Received:
    61
    The variable is not set when you're trying to use it. I'm on my phone or I'd edit the fiddle for you but you need to manipulate the DOM after its loaded. Alternatively use a server side method
     
    • Thanks Thanks x 1
  3. Mutikasa

    Mutikasa Power Member

    Joined:
    May 23, 2011
    Messages:
    579
    Likes Received:
    207
    Are you saying that this fiddle is first loading the html part then javascript part?
    In the en I put everything in HTML window, but then I dont understand why is Javascript window for
     
  4. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    With the second drop-down box on the left side you select where the javascript is placed in the output html. Currently it puts the script inside the onLoad event, which will exectue after the document is loaded.
    Select "No wrap - in <head>" and it will work.
     
    • Thanks Thanks x 2
  5. towelfox

    towelfox Junior Member

    Joined:
    Jan 11, 2012
    Messages:
    175
    Likes Received:
    61
    Yes that's right. The js window acts like an external JavaScript file. Its quite OK to use inline scripts as you've ended up doing, but the JavaScript window let's you manipulate the page after it's been loaded. In your example you could give an id to the <p> tag <p id="name"> - you can then manipulate that with JavaScript after the document has loaded
     
    • Thanks Thanks x 1
  6. Mutikasa

    Mutikasa Power Member

    Joined:
    May 23, 2011
    Messages:
    579
    Likes Received:
    207
    oh man, so simple...