Programmerdave Programmerdave - 3 months ago 9
jQuery Question

jquery .animate not working in my HTML

My jquery is not working in a simple project I am making for some of my students. I have a previous project I just ran which works just fine. The problem is that when i click on the div (there is only one) nothing happens and it should slide. Any help would be apricated.

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
$(document).ready(function(){
$("#frog").click(function() {
$( "#frog" ).animate({height: "20px"}, 500);
});
});
</script>
<style type="text/css">
#frog{
width: 100px;
height: 100px;
background-color: red;
position: relative;
left: 10px;
}
</style>
<title>I hate JS!</title>
</head>

<body>
<ul>
<h2>Programming Languages</h2>
<li>Python</li>
<li>Javascript</li>
<li>C++</li>
<li>C#</li>
<li>ruby</li>
</ul>
<ol>
<h2>Top 3 Best Animations</h2>
<h4><li>Slide</li></h4>
</ol>
<div id="frog"></div>
</body>

</html>

Answer

Your script tag has both a src and content:

<script type="text/javascript"src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js">
    $(document).ready(function(){
        $("#frog").click(function() {
            $( "#frog" ).animate({height: "20px"}, 500);
        });
    });
</script>

Per HTML specifications, it can have one or the other, but not both. Separate it into two elements:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $("#frog").click(function() {
            $( "#frog" ).animate({height: "20px"}, 500);
        });
    });
</script>
Comments