0

I am using Notepad++ and when I save and run this code in the browser the Jquery does not work.

<!DOCTYPE html>
<html>
<head>
<title>Result</title
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<link rel='stylesheet' type='text/css' href='style.css'/>
    </head>
    <body>
    <script>
    $(document).ready(function() {
    $("div").click(function() {
        $("div").fadeout('slow');
    });
}); 
</script>
        <div></div>  
        </script>
    </body>
</html>

Style.css

div {
    height: 100px;
    width: 100px;
    background-color: #FA6900;
    border-radius: 5px;
}
9
  • add some text in the div & recheck Commented May 6, 2017 at 16:45
  • 1
    Also there is an extra closing </script> tag after your div and the function is fadeOut() not fadeout() JS is case sensitive Commented May 6, 2017 at 16:47
  • Tried and still nothing. Commented May 6, 2017 at 16:48
  • 1
    <title> tag also not closed. Commented May 6, 2017 at 16:50
  • 1
    close your title tag Commented May 6, 2017 at 16:51

1 Answer 1

3

Replace fadeout with fadeOut

EDIT: As comments suggested, your title tag needs to be closed too.

$(document).ready(function() {
  $("div").click(function() {
    $("div").fadeOut('slow');
  });
});
div {
  height: 100px;
  width: 100px;
  background-color: #FA6900;
  border-radius: 5px;
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div></div>

Also you can replace the inner $(div) with $(this) if you just want the clicked div to fadeout

$(document).ready(function() {
  $("div").click(function() {
    $(this).fadeOut('slow');
  });
});
div {
  height: 100px;
  width: 100px;
  background-color: #FA6900;
  border-radius: 5px;
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div></div>

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.