Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript AJAX Basics (retiring) AJAX and APIs Adding jQuery

Ben Ahlander
Ben Ahlander
7,528 Points

404 error

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>AJAX Flickr Photo Feeder</title>
  <link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="css/main.css">
  <script src="http://code.jquery.com/jquery-1.11.0.min/js"></script>
  <script src="js/flickr.js"></script>


</head>
<body>
  <div class="grid-container centered">
    <div class="grid-100">
      <div class="contained">
        <div class="grid-100">
          <div class="heading">
            <h1>Flickr Photo Feeder</h1>
            <p>Choose which kind of animal you'd like to return photos of...</p>
          </div>
          <ul class="filter-select">
            <li><button>Dog</button></li>
            <li><button>Cat</button></li>
            <li><button>Moose</button></li>
          </ul>
        </div>

        <div id="photos">

        </div>
      </div>
    </div>
  </div>
</body>
</html>
$(document).ready(function(){
  $('button').click(function(){
    $(this).addClass("selected");
  });//end click
})//end ready

Why is this not adding the "selected" class to the buttons that get clicked?

1 Answer

Hello Ben Ahlander,

I noticed a few things that could be the problem. 1st one you do not have a . at the end of your js script, you seem to have a /

<!-- Common mistype is all.-->
  <script src="http://code.jquery.com/jquery-1.11.0.min/js"></script>

Also in your Javascript Code is missing a ; at the end

<script>
$(document).ready(function(){
  $('button').click(function(){
    $(this).addClass("selected");
  });//end click
//here you are missing the ;
})//end ready
</script>

Example

<script>
$(document).ready(function(){
  $('button').click(function(){
    $(this).addClass("selected");
  });  //end click
});  //end ready
</script>

Not sure if that will work for you or not. the JQuery library you are using is older as well here is a more up-to-date one if all else fails

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

let me know if this helps!

Ben Ahlander
Ben Ahlander
7,528 Points

That worked! Thanks a ton!