How to call a JavaScript function, declared in <head>, in the body when I want to call it

The Solution to How to call a JavaScript function, declared in <head>, in the body when I want to call it is


You can call it like that:

<!DOCTYPE html>
<html lang="en">
    <head>
        <script type="text/javascript">
            var person = { name: 'Joe Blow' };
            function myfunction() {
               document.write(person.name);
            }
        </script>
    </head>
    <body>
        <script type="text/javascript">
            myfunction();
        </script>
    </body>
</html>

The result should be page with the only content: Joe Blow

Look here: http://jsfiddle.net/HWreP/

Best regards!

~ Answered on 2012-01-07 22:31:29


Most Viewed Questions: