Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
How to combine javascript modules with javascript code in html

In my application I have my javascript in files. I am trying to convert those files to javascript modules.

I need to have some code in my html (in order to generate Django urls - (see this question How to configure a django url correctly in javascript).

html

<html>
    <head>
    </head>
    <body>
        <p id="display_text">aaa</p>
    </body>

    <script type="">
        function setText(text) {
            var display_text = document.getElementById('display_text');
            display_text.innerText = text;
        }
    </script>
    <script type="" src="module.js"></script>
</html>

module.js

setText('module')

This does not seem to work with modules

If I convert the html as follows

<script type="module">
    export function setText(text) {
        var display_text = document.getElementById('display_text');
        display_text.innerText = text
    }
</script>
<script type="module" src="module.js"></script>

I get the error

module.js:1 Uncaught ReferenceError: setText is not defined

If I need to import the setText function into module.js, how do I do it?

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!