Gajju Gajju - 7 months ago 8
HTML Question

Is it possible to define a function in <body> tag of <html> and call it form the <script> tag

I am new to HTML and Javascript, and I have a strange doubt

Is it possible to define a function in "body" tag of html and call it form the "script" tag

Till now i am trying this...

<!DOCTYPE html>
<html>
<head>
<script>
myFunction()
</script>
</head>

<body>
function myFunction()
{
alert("Hello World!");
}

</body>
</html>

Answer

No not possible. Browser only understands javascript within the <script> tag.

Comments