2015-04-01 22:05:05 +02:00
|
|
|
# .cadoles-slide-title[API du DOM (4/5)]
|
2015-03-31 23:29:23 +02:00
|
|
|
|
|
|
|
**Gestion des évènements**
|
|
|
|
|
|
|
|
```html
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<button id="my-button" onclick="myButtonClickHandler()"></button>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
```
|
|
|
|
```js
|
|
|
|
var myButton = document.getElementById('my-button');
|
|
|
|
|
|
|
|
// Méthode classique via les attributs (voir HTML)
|
|
|
|
function myButtonClickHandler(evt) {
|
|
|
|
console.log(evt);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Enlever le listener
|
|
|
|
myButton.onClick = null;
|
|
|
|
|
|
|
|
// via addEventListener
|
|
|
|
|
|
|
|
myButton.addEventListener('click', myButtonClickHandler);
|
|
|
|
|
|
|
|
// Enlever le listener
|
|
|
|
myButton.removeEventListener('click', myButtonClickHandler);
|
|
|
|
```
|