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 Tawil
1,922 PointsWhy are we adding the attr to the $image varaible
Based on how I believe a file is read. Top to bottom. How is the imageLocation being added to the $image.
So We appened the $image to the $overlay and then append the $overlay to the body. We've added the following to our page.
<div id=overlay"><img></div>
We then get the imageLocation and add it to the src of our $image variable. Therefore, our $image variable is <img src="(imageLocation")>
Since this is at line 17 and appending the $overlay was on line 11, then it shouldn't effect line 11 and thus it would never be added to our body?
1 Answer
Nejc Vukovic
Full Stack JavaScript Techdegree Graduate 51,574 PointsHi John.
If you check the .attr functions documentation .attr() you can see how this method is supposed to be used and the whole purpose of the method is written in detail.
If you check it you'll get what I mean.
The code is read from top to bottom always but if you have something down the line that affects the previous code thos will be evaluated and executed.
In short the .attr() method: Get the value of an attribute for the first element in the set of matched elements or set one or more attributes for every matched element.
If you have a problem getting by the challange here's a little help:
$image.attr("src", imageLocation);
Hope I helped. And sorry it took me so long to answer.
Happy Coding!!!