nilkkiz
nilkkiz

Reputation: 41

Including js file in handlerbar

I am not able to recieve any calls to my js file. What could be the problem? Using MVC

view, file.hbs

<div class="container">
  <h2 onClick="test()">Title</h2>
  {{>list}}
</div>

<script src='/public/js/game.js' type='text/javascript'></script>

public game.js file

function test(){
   alert("alert");
}

router file

'use strict';

 const express = require('express');
 const router = express.Router();
 const GameController = require('../controllers/game');

 router.get('/', GameController.initialize);

 module.exports = router;

Upvotes: 0

Views: 24

Answers (1)

Sebastian Brunner
Sebastian Brunner

Reputation: 26

A function cannot be called unless it was defined in the same file or one loaded before the attempt to call it. Means, you need to move the script-tag before the div-tag and it should work. The console should also give you some hints.

Upvotes: 1

Related Questions