I think that you are unneccessarily harsh and dismissive in your judgement of w3schools. The reality is that many thousands of people have found it a valuable resource over many years (and doubtless still do). It is indeed a little dated (in a few but not most respects), but to say that it only useful for users of Nescape 4 is simply silly. How many million times have I told you not to exaggerate? As so often, your opinions are unmodulated.
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.