Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

232
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda