I've been given an assignment to create an external JavaScript code file to correspond to an HTML code file already created by my instructors:
I'm supposed to make the buttons listed in the HTML code change a box graphic: "button1" to grow the box; "button2" to make the box blue; "button 3" to make the color of the box fade away; and "button4" to reset the box to its original size and color.
$("#button1").on("click", function() {
$("#box").animate({
height: "+=50px",
width: "+=50px"
},
"fast");
});
$("#button2").on("click", function() {
$("#box").animate().css({
backgroundColor: "blue"
});
});
$("#button3").on("click", function() {
$("#box").fadeOut();
});
$("#button4").on("click", function() {
$("#box").fadeIn("fast").animate({
height: "150px",
weight: "150px"
},
"fast").css({
backgroundColor: "orange"
});
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<title>Jiggle Into JavaScript</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js">
</script>
</head>
<body>
<p>Press the buttons to change the box!</p>
<div id="box" style="height:150px; width:150px; background-color:orange; margin:25px"></div>
<button id="button1">Grow</button>
<button id="button2">Blue</button>
<button id="button3">Fade</button>
<button id="button4">Reset</button>
</body>
</html>
I'm reading all kinds of conflicting ways to create this JavaScript code. Am I missing the "getElementById" function to make these buttons work? Or some other function?