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 trialGrace Provost
7,698 PointsButton does not stay clicked and photos do not show
Compared line by line multiple times and may have missed something.
$(document).ready(function() {
// user clicks button
$("button").click(function() {
$("button").removeClass("selected");
$(this).addClass("selected");
// JS obtains word on the button
var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
var animal = $(this).text();
var flickerOptions = {
tags: animal,
format: "json"
};
// add a link and <img> to the page, receive JSON response
var displayPhotos = function(data) {
var photoHTML = '<ul>';
$.each(data.items, function(i, photo) {
photoHTML += '<li class="grid-25 tablet-grid-50">';
photoHTML += '<a href="' + photo.link + '" class="image">';
photoHTML += '<img src="' + photo.media.m + '"></a></li>';
}); // end loop
photoHTML += '</ul>';
$('#photos').html(photoHTML);
} // end function displayPhotos
// make a GET request to Flickr, sending the word
$.getJSON(flickerAPI, flickerOptions, displayPhotos);
}); // end button click
}); // end ready
2 Answers
Robert Leonardi
17,151 PointsHey Grace,
Why do you want to have the button stay clicked? What are you trying to achieve?
I've tried your code and it runs great. The pics are showing. I add "$('#photos').empty();" before displaying the pics, just so i can always have the updated pics whenever I clicked the button.
Best of luck
Caitrin Roesler
7,671 PointsI am having the same issues as Grace. This answer above did not help....