Hello,
Should I add a semicolon at the end of the line I quoted as below?
>
divs[1].addEventListener(‘click’, fn)
I’ve tested both work. What’s the standard about this writing?
Thank you!
[code]
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<title>Document</title>
<style>
div {
width: 100px;
height: 100px;
margin: 10px auto;
background-color: pink;
}
</style>
</head>
<body>
<div>1</div>
<div>2</div>
<div>3</div>
<script>
var divs = document.querySelectorAll(‘div’);
divs[0].onclick = function (){
alert(‘hello’);
divs[0].onclick = null;
}
divs[1].addEventListener(‘click’, fn)
function fn(){
alert(‘I am two’);
divs[1].removeEventListener(‘click’,fn);
}
</script>