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 trialjohn larson
16,594 PointsTrying to practice using refactor, need insight please
practice project
$("#img .photo-1").click(function(){
$("#img .photo-1").fadeOut(500).hide()
$("#img .photo-2").fadeIn(300).show()
$("#img .photo-2").click(function(){
$("#img .photo-2").fadeOut(500).hide()
$("#img .photo-3").fadeIn(300).show()
$("#img .photo-3").click(function(){
$("#img .photo-3").fadeOut(500).hide()
$("#img .photo-4").fadeIn(300).show()
$("#img .photo-4").click(function(){
$("#img .photo-4").fadeOut(500).hide()
$("#img .photo-1").fadeIn(300).show()
})
})
})
})
2 Answers
john larson
16,594 PointsI looked at that, thank you. I think it's using classes as a way to show and hide w/out repeating all the selectors? Is that a general idea there? Or are you saying don't ask those kind of questions on this forum...
anil rahman
7,786 PointsNo, i just merely linked you a similar topic example, that you may be able to change in some way to adapt it to your own situation. I haven't done enough JQuery to say what is the right way and what is wrong when it comes to your problem.
john larson
16,594 PointsThanks Anil.
john larson
16,594 Pointsjohn larson
16,594 Pointsthe code works but I know it can be more concise, nothing I've tried works