mirror of
https://github.com/microsoft/frontend-bootcamp.git
synced 2026-01-26 14:56:42 +08:00
Fix JS syntax, improve wording about onclick
This commit is contained in:
@@ -107,7 +107,7 @@ window.onclick = function() {
|
|||||||
|
|
||||||
> Note that only a single function can be assigned to `onload`, but many event listeners can be added for `load`.
|
> Note that only a single function can be assigned to `onload`, but many event listeners can be added for `load`.
|
||||||
|
|
||||||
In our example, we want to trigger a function when a button is clicked. To do this, we first need to get a reference to the button. We can use the [`querySelector`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) method of the browser-provided [`document`](https://developer.mozilla.org/en-US/docs/Web/API/Document) global variable to get that reference, and then we can set its `onclick` value just like above.
|
In our example, we want to trigger a function when a button is clicked. To do this, we first need to get a reference to the button. We can use the [`querySelector`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector) method of the browser-provided [`document`](https://developer.mozilla.org/en-US/docs/Web/API/Document) global variable to get that reference. Then we can set our `displayMatches` function to be the button's `onclick` handler.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const button = document.querySelector('.submit');
|
const button = document.querySelector('.submit');
|
||||||
@@ -164,7 +164,7 @@ First we need to get a reference to the email field in our app's DOM. To do this
|
|||||||
function displayMatches() {
|
function displayMatches() {
|
||||||
const email = document.getElementById('email');
|
const email = document.getElementById('email');
|
||||||
console.log(email);
|
console.log(email);
|
||||||
...
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ function displayMatches() {
|
|||||||
const email = document.getElementById('email');
|
const email = document.getElementById('email');
|
||||||
const text = email.value;
|
const text = email.value;
|
||||||
console.log(text);
|
console.log(text);
|
||||||
...
|
// ...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -185,7 +185,7 @@ Now that we've read values from the DOM and fed that into our matching logic, we
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function displayMatches() {
|
function displayMatches() {
|
||||||
...
|
// ...
|
||||||
const submit = document.querySelector('.submit');
|
const submit = document.querySelector('.submit');
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@@ -194,7 +194,7 @@ Now that we have a reference to the submit input, we can set its value contain t
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function displayMatches() {
|
function displayMatches() {
|
||||||
...
|
// ...
|
||||||
const submit = document.querySelector('.submit');
|
const submit = document.querySelector('.submit');
|
||||||
submit.value = matches + ' matches';
|
submit.value = matches + ' matches';
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ We could also have done this in a single line as follows:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function displayMatches() {
|
function displayMatches() {
|
||||||
...
|
// ...
|
||||||
document.querySelector('.submit').value = matches + ' matches';
|
document.querySelector('.submit').value = matches + ' matches';
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user