Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
Igor Kałużny4,337 Points
Why do we have to do this:
var imageLocation = $(this).attr("href"); $image.attr("src", imageLocation);
instead of this:
I know that it probably won't work, but can smn explain the logic to me please?
Stephan Olsen6,650 Points
Your example wouldn't work. If you wanted to shorten it down to one line, it would look like this:
It's perfectly valid code, but it is much harder to read. It's good practice to break down your code in smaller pieces for more readability. This makes the code much easier to maintain when going back and looking at old code.
Christopher DeboveCourses Plus Student 18,372 Points
Pointing your solution
This line of code would set the src attribute at the value "href", not what you want. Stephan Olsen gave you a good method if you want to shorten your code if that's what you want.