dcsimg
www.webdeveloper.com
Results 1 to 4 of 4

Thread: JavaScript not rendering if place inside the body tag?

  1. #1
    Join Date
    Apr 2011
    Location
    Outer Space
    Posts
    7

    Question JavaScript not rendering if place inside the body tag?

    Hi humans!
    I'm a JavaScript newbie and new here.
    I've learned so far that JavaScript can be placed anywhere between the <head></head> or <body></body> tag in an HTML document. I've been doing some exercises Alerts: I placed my JavaScript code between the head section of my page and it works fine, but when placed between the body tags; the browser seems to just ignore it. Nothing happens.

    Can someone explain me why is this?

  2. #2
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    please post an example.

  3. #3
    Join Date
    Apr 2011
    Location
    Outer Space
    Posts
    7

    Red face BinaryTrek Example

    It works fine if I place the code inside the head section:

    HTML Code:
    <!DOCTYPE html>
    
    <html lang="en">
    
    <head>
     <title>Web Page title</title>
    
    <script>
    function yetAnotherAlert(){
    alert("hello World");
    }
    </script>
    
    </head>
    <body>
    </body>
    </html>
    and why it doesn't if I place the code between the body section of the document; nothing happens! Anybody??
    example:


    HTML Code:
    <!DOCTYPE html>
    
    <html lang="en">
    
    <head>
     <title>Web Page title</title>
    
    </head>
    <body>
    
    <script>
    function yetAnotherAlert(){
    alert("hello World");
    }
    </script>
    
    
    </body>
    </html>

  4. #4
    Join Date
    Jul 2003
    Location
    The City of Roses
    Posts
    2,503
    Neither of your examples ever calls the yetAnotherAlert function, so right now, neither example does anything. I suspect the code you posted isn't the code you're actually working with. Post your actual code, then maybe we can help.
    for(split(//,'))*))91:+9.*4:1A1+9,1))2*:..)))2*:31.-1)4131)1))2*:3)"'))
    {for(ord){$i+=$_&7;grep(vec($s,$i++,1)=1,1..($_>>3)-4);}}print"$s\n";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles