Previously, i have a hard time flashing message and fading after some time. I now succeeded with DOM. My major problem now is to put the DOM file on the pug head to work like regular html. I tried that and its not working please help thank you.
//pug
DOCTYPE
html(lang="eng")
head
title Home Page
meta(name='description', content='Preparing Personal Portfolio')
meta(charset='utf-8')
meta(http-equiv='X-UA-Compatible', content='IE=edge')
meta(name='viewport', content='width=device-width, initial-scale=1')
script(src="./my-script.js")
header
h1
small nanas personal portfolio looksup for presentation
h2.center#welcome Welcome, #{username}!
body
a(href="/register") register
br
a(href="/login") login
document.addEventListener('DOMContentLoaded', function() {
// this function runs when the DOM is ready, i.e. when the document has been parsed
var sellct = document.querySelector('h2');
sellct.textContent =
'registered succesful!'
setTimeout(function() {
sellct.remove();
}, 1500);
});
Do you mean the DOM WONT WORK, if h2 is not in the body?? and header cannot be on the same level with head.
Ok Annestesia, can you please show me the correct way to do it, or at least go by my worries. Give me a code on how to serve my DOM script file in a pug html, cause like you see i serve it like i did in a regular html and nothing work. But this whole work in a regular html. thank you.
Well browser will fix many html errors, honestly i dont know how crucial this is , but if theres a working code why not use it
think pug script code is ok, try to move header and its content(h1,h2) inside body (standard html structure), maybe move script to the end of body(after all other code), indentation must be consistent !
this is schematic structure
head
meta
meta
body
header
h1
h2
a
br
a
script(src='path/to/script')
make sure that the path is correct
think it’ll be ../my-script.js (you need to go one level up)