Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

553
Visualizações
how to compose html code within onload() function?

Within body I have 3 div: menu, submenu, detail. I'm using script load_menu() in menu div to load html code to submenu div. I'm using script load_data() in submenu div to load html code to detail div. In both scripts I use the fetch method. Up to now everything works fine.

I would like to load the first submenu item after loading submenu div, using onload() function. I don't know how to reform the submenu line into proper syntax in the onload() function.

Next is parts from my code:

  1. scrips definition:

<script>
    function load_menu(htmname) {
        fetch(htmname /*, options */)
            .then((response) => response.text())
            .then((html) => {
                document.getElementById("submenu").innerHTML = html;
            })
            .catch((error) => {
                console.warn(error);
            });
    }
    function load_data(htmfile) {
        fetch(htmfile /*, options */)
            .then((response) => response.text())
            .then((html) => {
                document.getElementById("detail").innerHTML = html;
            })
            .catch((error) => {
                console.warn(error);
            });
    }
    
    function loadfirst() {
          /*  load_data("./iNat_files/PID297.html"); ???? */
    }
</script>

/* menu item executed onclick */
<li><a href="#submenu" onclick=load_menu("./iNat_files/P_menu.html") onload="loadfirst()">Plants</a></li>

/* the first submenu item to fetch - to be adapted and reformed for use with onload() */
<li><a href="#detail" onclick=load_data("./iNat_files/PID297.html")># 297:  = Centaurea crocodylium</a></li>

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda