I just started learning JavaScript. I just want to build an image carousel but I get an error at my first line:
Uncaught TypeError: Cannot read property 'getAttribute' of null
js:
function changeImage(){
var imageSrc=document.getElementById("image").getAttribute("src");
}
changeImage();
html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="hello.js"></script>
<title></title>
</head>
<body>
<div id="button_left">
<img id ="left" src="left.png">
</div>
<div id="button_right">
<img id ="right" src="right.png">
</div>
<div class="container">
<img id ="image" src="1.jpg">
</div>
<div id="result"></div>
</body>
</html>