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

398
Vistas
Agregar script/css a DOM usando Javascript

Tibco está eliminando JQuery de Spotfire y tengo algunos paneles que dependen de Jquery para funcionar, como se muestra a continuación:

 var css = "https://localhost/css/style.css";

if (!$('link[href="' + css +'"]').length) {
 $("<link/>", { "rel": "stylesheet", "type": "text/css", "href": css }).appendTo("head");
}

Me gustaría hacer lo mismo usando Javascript, pero no pude encontrar una solución que me permitiera cargar el CSS solo si no existe en DOM.

almost 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

Cualquier selector que funcione en jQuery funcionará con el método document.querySelector .

Algo como esto:

 if (!document.querySelector(`link[href='${css}']`)) {
 document.head.innerHTML += `<link rel="stylesheet" href="${css}" type="text/css"/>`;
}

almost 4 years ago · Santiago Trujillo Denunciar

0

const cssHref = "https://localhost/css/style.css";

// If element not found returns `null`
const stylesheet = document.querySelector(`link[href="${cssHref}"]`)
if (!stylesheet) {
 // You can create your own helper function to simplify the creation of the element
 // instead of manually creating the <link> element
 const style = document.createElement('link')
 style.rel = 'stylesheet'
 style.href = cssHref

 document.head.append(style)
}
almost 4 years ago · Santiago Trujillo Denunciar
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