SCRIPT and LINK tags defined in HEAD incorrectly assigned to BODY
See original GitHub issueIt appears the script
and link
tags defined in the head
section are incorrectly being placed in the body
DOM tree when using selectors to find them. On the plus side this doesn’t apply to $('body').html()
text, but it does make using cheerio to build up template pages impossible without either duplicating script
and link
tags (i.e. when you’re passing the links up and searching for script
and link
tags via body > script
or body > link
) or adding additional markup to concatenate the script
and link
head
elements (like moving them outside of the head into a div
contained in the body
.
This does work in standard jQuery (i.e. you can use head > link
and head > script
to obtain either.
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
script tag doesn't work in head tag - Stack Overflow
Any JS written in the head will be parsed before the body begins to load, so any JS statements referencing body elements will...
Read more >Scripts in HTML documents - W3C
The SCRIPT element places a script within a document. This element may appear any number of times in the HEAD or BODY of...
Read more >What's in the head? Metadata in HTML - MDN Web Docs
The HTML head is the contents of the <head> element. Unlike the contents of the <body> element (which are displayed on the page...
Read more >1. Loading and Execution - High Performance JavaScript [Book]
The HTML 4 specification indicates that a <script> tag may be placed inside of a <head> or <body> tag in an HTML document...
Read more >Custom code in head and body tags - Webflow University
<link>, <meta>, and <style></style> tags should always go inside the <head> tag. <script></script> tags can also be added inside the <head> tag, but...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Upon closer inspection this only occurs when you have a custom element preceeding the tags in the
head
tag, for instance:In the example above the
link
tag will show up but thescript
tag gets moved into the body (but not in thebody
HTML.) This differs from jQuery, which will always place it in thehead
tree.Additional note: it does actually copy the non-standard tags into the start of the
body
html (for instance theheader
tag above,) but doesn’t not copy the other elements into thebody
.You can add any tags inside template.