Forum Moderators: open
The last time I checked, when I'm writing ES2015+, if I add an EventListener to a DOM Node which then runs a function, then... only the bits of the DOM that I want to change get updated.
Virtual DOM is, by definition, slower than carefully crafted manual updates, but it gives us a much more convenient API for creating UI.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello JavaScript!</title>
</head>
<body>
<div id="example"></div>
<script>
document.getElementById("example").innerHTML = "<h1>Hello, world!</h1>";
</script>
</body>
</html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello React!</title>
<script src="build/react.js"></script>
<script src="build/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
</head>
<body>
<div id="example"></div>
<script type="text/babel">
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('example')
);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Hello JavaScript!</title>
</head>
<body>
<div id="example"></div>
<script>
const example = document.getElementById("example");
const exampleHeading = document.createElement('h1');
exampleHeading.textContent = 'Hello, world!';
example.appendChild(exampleHeading);
</script>
</body>
</html>
You can fight windmills or embrace them.