Skip to content

Commit 22a782d

Browse files
committed
Update page/javascript-101/getting-started.md
Showing people inline event handlers as the first JavaScript example is promoting very bad and outdated methods. Having no DOCTYPE means you don't write HTML.
1 parent b7b9c05 commit 22a782d

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

page/javascript-101/getting-started.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,31 @@ In the browser, JavaScript adds interactivity and behavior to HTML content. With
2121
Look at this simple HTML page that includes CSS and JavaScript to see how it all fits together:
2222

2323
```
24-
<html>
24+
<!DOCTYPE HTML>
25+
<html lang="en-US">
2526
<head>
27+
<meta charset="UTF-8">
2628
<title>Hello World</title>
2729
<!-- CSS for presentation -->
2830
<style type="text/css">
2931
h1 { font-size: 14px; color: hotpink; }
3032
button { color: red; }
3133
</style>
32-
<!-- JavaScript for interactivity -->
33-
<script type="text/javascript">
34-
function buttonClick() {
35-
alert("Hello!");
36-
}
37-
</script>
3834
</head>
3935
<body>
4036
<h1>Hello World</h1>
41-
<button onClick="buttonClick();">Click Me!</button>
37+
<button>Click Me!</button>
38+
39+
<!-- JavaScript for interactivity -->
40+
<script>
41+
// get a handle on the first button element
42+
// in the document.
43+
var button = document.querySelector('button');
44+
// if a user clicks on it, say hello!
45+
button.addEventListener('click', function(ev) {
46+
alert('Hello');
47+
}, false);
48+
</script>
4249
</body>
4350
</html>
4451
```

0 commit comments

Comments
 (0)