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

200
Views
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
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!