0

i have 2 files....one html and one js....

html code:

<!DOCTYPE html
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <script type="text/javascript" src="external.js"></script>

    <title> Sign In And Registration Page </title>
</head>

<body>

    <div id="headerTag">
    </div>

    ///codes here....

</body>
</html>

js code: some functions here performed on click operation.....

 function onClickOperation ()
    {
        ///here codes..
    }

problem is that the functions are not being called...when i put the same js code in the html file directly, it works....what do i have to do to load those functions from separate js file?

TrioHaydos
  • 41
  • 1
  • 3

2 Answers2

1

external.js should have the code called after DOM has finished loading like so

document.addEventListener('DOMContentLoaded',function(){
// code here
});

or it should be included inside the body tag below the DOM elements it should interact with

0

Try wrapping the script in the body and just before the </body> tag:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title> Sign In And Registration Page </title>
</head>
<body>

    <div id="headerTag">
    </div>

    ///codes here....
    <script type="text/javascript" src="external.js"></script>
</body>
</html>
Gobbin
  • 530
  • 3
  • 17