0

I'm using Javascript and jQuery for the first time and I don't know what I am doing wrong. I have a homework assignment that gives me the .html document where I added the line.

Here is my .html

<!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>

    <script type="text/javascript" src="javascript.js"></script>
    <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.mins.js"></script>
</body>

Here is my .js file

function index(){

    var $box = $('#box');
$("#button1").click(function(){
    $("#box").animate({height: 300px});
});
   $("#button2").click(function(){
      $("#box").css("color", "blue");
 });
  $("#button3").click(function(){
       $("#box").fadeOut();
 });
 $("#button4").click(function(){
      $("box").end();
 });
 };
 $(document).ready(index);
2
  • Not totally clear what you want the code to do or what the problem is - can you clarify please? Commented Aug 31, 2017 at 13:24
  • 6
    Import jQuery before your script; the order is important. Keep your browser developer console open so that you see errors (hit f12). Commented Aug 31, 2017 at 13:24

1 Answer 1

1

function index(){

    var $box = $('#box');
$("#button1").click(function(){
    $("#box").animate({height: '300px'});
});
   $("#button2").click(function(){
      $("#box").css("background-color", "blue");
 });
  $("#button3").click(function(){
       $("#box").fadeOut();
 });
 $("#button4").click(function(){
      $("box").end();
 });
 };
 $(document).ready(index);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<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>

you are providing string value to height, you need to enclose 300px in inverted commas, also if you trying to change background color than use backgroundColor or background-color property, color is used to change color of texts.

these are some common mistake you've done, also consider what "pointy" has suggested you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.