Heimot
Heimot

Reputation: 61

How can i call a javascript function from a file for pug?

Heres my code but removed some changed code to something smaller!

Javascript code:

// /JS
function callme() {
var test = 1
alert(test);
}

Pug code:

// /first.pug
var funct = require('../JS');
button(onclick='clickme()') click   
script.
function clickme() {¨
// trying to call callme function from my javascript file but i really dont know how.
    callme();
}

Sorry about this question i dont use pug but this was already made with pug so i cannot go changing it since it has alot more code but didnt post all not needed code here.

Upvotes: 1

Views: 3538

Answers (1)

Quentin
Quentin

Reputation: 943569

Pug has no capability to directly run JavaScript. It is used to generate HTML.

You are already generating HTML with embedded client-side JavaScript.

You need to write the HTML to include the external JavaScript.

i.e. <script src="/url/to/JS.js"></script>

In Pug that would be:

script(src="/url/to/JS.js")

Make sure your HTTP server gives the JS a public URL!

Upvotes: 5

Related Questions