Reputation: 1663
How could I put this css file <link rel="stylesheet" href="/path/to/my/main.css">
inside head
tag using Node?
This is what I did so far:
response.writeHead(200,{
'Content-Type' : 'text/html',
});
response.end('<link rel="stylesheet" href="/path/to/my/main.css">');
That winds up doing this:
<body><head><link rel="stylesheet" href="/path/to/my/main.css"></head></body>
How can I get the link and head elements outside of the body element where they should be?
Upvotes: 0
Views: 172
Reputation: 14866
You can try this:
response.end('<link rel="stylesheet" href="/path/to/my/main.css"><body>Your page here</body>');
or this:
response.end('<link rel="stylesheet" href="/path/to/my/main.css"><div>Your page here</div>');
Browsers will automatically put every tags into head
until they catch a tag, which is only used inside body
by default (body,span,div,...)
. Then they move the rest of the page into body
tag.
Upvotes: 1
Reputation: 1213
if you want to include the tag using javascript, try this:
var el = document.createElement("link");
el.setAttribute("rel", "stylesheet/less");
el.setAttribute("type", "text/css");
el.setAttribute("href", "path_to_my_css.css");
document.head.appendChild(el);
Upvotes: 1