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 trialLuis Marsano
21,425 PointsIs setting a boolean attribute to true valid?
From the video, I see this sets the attribute value to the string 'true' in the DOM. According to the HTML specification
If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.
The values "true" and "false" are not allowed on boolean attributes. To represent a false value, the attribute has to be omitted altogether.
And XML specifications accept only the full attribute name.
I understand all major browsers will accept attribute='true'
, and I wouldn't stop anyone from doing it; however, an exercise is trying to make me put .attr('download', true)
when the standards indicate otherwise. The download
attribute is somewhat odd, since it's not even boolean:
The download attribute, if present, indicates that the author intends the hyperlink to be used for downloading a resource. The attribute may have a value; the value, if any, specifies the default file name that the author recommends for use in labeling the resource in a local file system.
Compliant web-browsers would offer the name 'true' for the file to save. As a separate matter, that exercise may need some attention.
2 Answers
Steven Parker
231,236 PointsIt looks like you've discovered a course bug! You might want to submit this directly to the staff using the procedure described on the Support page.
Rob Allessi
8,600 PointsThanks, Luis! We'll look into it. We're currently on a company retreat, so this investigation will likely be delayed until next week.
Luis Marsano
21,425 PointsLuis Marsano
21,425 PointsThanks!
Saud Tauqeer
Courses Plus Student 8,099 PointsSaud Tauqeer
Courses Plus Student 8,099 Pointsis there any other way than giving attr.('download' true);
Steven Parker
231,236 PointsSteven Parker
231,236 PointsApparently, it's not a boolean value, so the jQuery way would be "
.attr('download', '')
".You can also assign the property with plain JavaScript or just add it to the HTML tag.
Luis Marsano
21,425 PointsLuis Marsano
21,425 PointsAccording to the spec for
download
The spec for boolean attributes says
So compliant alternatives would be
.attr('download', '')
.attr('download', filename)