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

167
Views
¿Cómo puedo agregar un elemento después de otro en el encabezado del documento?

Necesito inyectar elementos de estilo en la sección principal de mi html usando JavaScript. Para algún contexto, estoy usando webpack para inyectar estilos. Tengo una función que se supone que inyecta estilos en una identificación dentro de las etiquetas de mi cabeza.

Así es como se ve mi html:

 function insertAtElement(element) { var target = document.getElementById( "inject-theme-styles-here" ); target.appendChild(element); }
 <head> <meta charset="UTF-8" /> <title>Webpack tutorial</title> <noscript id="inject-theme-styles-here"></noscript> </head> <body> <div id="root"></div> </body>

No obtengo el resultado deseado. En la pestaña del elemento en cromo lo agrega dentro de la etiqueta. Pero necesito que se agregue justo debajo, no dentro.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Si desea que su elemento se agregue después de target , en lugar de usar target.appendChild(element); que agrega un elemento secundario al objetivo, use lo siguiente:

 target.parentNode.insertBefore(element, target.nextSibling);
about 4 years ago · Juan Pablo Isaza Report

0

Cree manualmente un script, configure el atributo src y colóquelo dentro del encabezado usando el nombre de la etiqueta (o querySelector si lo desea)

 // create a script element let theScript = document.createElement("script"); // define it as javascript script theScript.setAttribute("type","text/javascript"); // set the src theScript.setAttribute("src","src/myscript.js"); // insert into the head document.getElementsByTagName("head")[0].appendChild(theScript);

about 4 years ago · Juan Pablo Isaza Report
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!