r/javascript • ⚛️⚛︎ • Apr 10 '23

React, Visualized

https://react.gg/visualized
478 Upvotes

33 comments sorted by

View all comments

Show parent comments

1

u/nvmnghia Apr 11 '23

Could you please cite some sources for the "get the handle of the element and update from there" part?

1

u/Snapstromegon Apr 11 '23

What do you mean with sources? How to do that or code examples that did this or sources that show that it was done that way?

1

u/nvmnghia Apr 11 '23

source that it was done that way please.

1

u/Snapstromegon Apr 11 '23

Just as one example (because I have it lying around and I don't just want to argument with some old code that I might still have):

This book from 2003 contains the following code example: https://www.amazon.de/HTML-Kompendium-XHTML-DHTML-Handbuch/dp/3827266580/ref=sr_1_3?__mk_de_DE=%C3%85M%C3%85%C5%BD%C3%95%C3%91&crid=3V5BZ0IOAAK6L&keywords=html+g%C3%BCnter+born&qid=1681235582&sprefix=html+g%C3%BCnter+born%2Caps%2C68&sr=8-3

<html>
  <head>
    <title>JavaScript</title></head>
  <script type="text/JavaScript">
    <!--

    function alter()
    {
      var text = "";
      var alter = prompt("Ihr Alter?", "18");
      if(parseInt(alter, 10) < 18)
        { text = "Kind"; }
      else
        { text = "Erwachsener"; }
      element.innerHTML = text;
    }  
    //-->
  </script>
  <body>
    <p id="ausgabe">Hier steht der Text</p>
    <input type="button" value="Alter" onClick="alter()">
    <script>
      <!--
        var element = document.getElementById("ausgabe");
      //-->
    </script>
  </body>
</html>

Please note the beauty of bracket placement, the <-- //--> and the explicit script type (the next chapter is about VB scripts in html).

Also while looking around I got flashbacks to the times of framesets and handcrafted php abominations from around 2005...