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

199
Vistas
script tag is created via jQuery.append but not with Javascript appendChild

I'm converting a jQuery script into Javascript but when I try to append via jQuery.append(data) it creates a proper script in head tag of page

jQuery

if (data) {
  $('head').append(data);
}

screenshot attached

while when I do it via Javascript it only appends the data as a string and not as a script tag

Javascript

  if (data) {
    appendTo("head", document.createTextNode(data));
  }

screenshot attached

If I try to append without document.createTextNode by simply doing

if (data) {
    document
      .getElementsByTagName("head")[0]
      .appendChild(data);
  }

then it throws following error

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

while data in has the following (JSON+LD) content

const data = "\n<script type=\"application/ld+json\">\n{\n  \"@context\": \"http://schema.org\",\n  \"@type\": \"BlogPosting\",\n  \"mainEntityOfPage\": {\n    \"@type\": \"WebPage\",\n    \"@id\": \"http://localhost:8080/?p=abbc\"\n  },\n  \"url\": \"http://localhost:8080/?p=abbc\",\n  \"headline\": \"How To workout.\",\n  \"datePublished\": \"2021-12-17T15:15:00-06:00\",\n  \"dateModified\": \"2022-05-31T11:01:15-05:00\",\n    \"author\": {\n    \"@type\": \"Person\",\n    \"name\": \"Laura\",\n    \"url\": \"http://localhost:8080/?a=laura\"\n  },\n      \"wordCount\": \"377\",\n  \"description\": \"Main description  . \"\n}\n</script>"
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