DEV Community

loading...

Discussion on: Implement Dark Mode On Your Website.

Collapse
manuthecoder profile image
π™ΌπšŠπš—πšžπšƒπš‘πšŽπ™²πš˜πšπšŽπš›

Instead of onload="onload()", I would prefer this, since you would only need to add one line to your page (<script src='script.js'></script>):

window.onload = function() {onload()}
Enter fullscreen mode Exit fullscreen mode

But otherwise, this is great!

Collapse
mattmarquise profile image
Matthew Marquise Author

Definitely works too! Thanks for the tip!

Collapse
prodexia profile image
Ultimate Coder

welcome , my pleasure!

Collapse
wdg profile image
Wesley De Groot • Edited

You should use event listeners if you want to be on the safe side window.onload can be overwritten and eventlistener adds an listener to the page and will not be overwritten

Collapse
mattmarquise profile image
Matthew Marquise Author

Good point. However for this demo I wanted to keep it simple. For those who are into JS and have more than one function set for onload, they should understand how it works. But eventlistener is a great alternative.