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 trial

JavaScript jQuery Basics Working with jQuery Collections Changing Element Properties

Code copied verbatim, but does not work.

I can see that $pdfs.attr('download', true); transfers the attribute of download and sets it to true in the elements of my console but the pdf file does not download. I have checked and double checked the syntax, root properties and everything else I could think of. Using chrome on a Ubuntu OS, could that have something to do with it? code as follows; const $odd = $('a:odd'); // $odd.hide(); const $secureLinks = $('a[href^="https://"]'); // $secureLinks.hide(); const $pdfs = $('a[href$=".pdf"]'); // $pdfs.hide();

// Open link in new tab $secureLinks.attr('target', '_blank'); // Download instead of opening in browser $pdfs.attr('download', true);

Brandyn Lordi
Brandyn Lordi
17,778 Points

Hi matt, Are you using chrome? If so, there is actually a hidden setting that might be the cause of your frustration :)

try this: Chrome settings > Content Settings > PDF documents > enable downloads.

Thank you Brandyn that was spot on my problem. Thank you very much.

2 Answers

Elias Guderian
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Elias Guderian
Front End Web Development Techdegree Graduate 14,994 Points

Hallo there, I had the same problem and I changed the setting and it still works so Reinhard Liess you are incorrect. I don't know anything about same-origin links though but I followed the instruction and it worked although it was kinda difficult to find the option. I don't really like googles settings layout.

Reinhard Liess
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Reinhard Liess
Full Stack JavaScript Techdegree Graduate 21,034 Points

Which version of Chrome do you use? According to Can I Use...

Chrome 65 and above only supports same-origin download links.

So that means that this example using a cross-site link won't ever work on Google Chrome (or Mozilla Firefox, for that matter.)