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

Hanane Ladj
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Hanane Ladj
Front End Web Development Techdegree Graduate 15,686 Points

What's wrong with my code ? the download attr doesn't not work

I am following the video and coding at the same time but the file does not download when i click on it

const $odd = $('a:odd'); const $secureLinks = $('a[href^="https://"]'); const $pdfs = $('a[href$=".pdf"]');

$secureLinks.attr('target', '_blanck'); //$pdfs.attr('target', '_blanck'); $pdfs.attr('download', true);

3 Answers

This part caught my attention:

$secureLinks.attr('target', '_blanck'); //$pdfs.attr('target', '_blanck'); $pdfs.attr('download', true);

From what i remember from HTML, when you use a target attribute to open a file its usually spelt as "_blank" and not "_blanck", i know seems really fiddly, but grammatical errors can cause your program to run unexpectedly. Try changing those to "_blank" and give it another go.

This is an example HTML code i created below, it basically creates a button that links to google using the blank target attribute value.

 <a href="https://www.google.com/" target="_blank">

   <button> Visit Google </button>

   </a>

I hope this has helped. Let me know.

Not a problem, glad that helped 😊

Hanane Ladj
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Hanane Ladj
Front End Web Development Techdegree Graduate 15,686 Points

Thank you so much for your time and help. You totally right about the grammatical error. However, i did not have a problem with the blank issue because it did open the external page. Now, i corrected the error ,but the issue with pdf still the same , it does not work. i have an issue with this code: $pdfs.attr('download', true); it seems like it is correct but when i click on the pdf form it does not download.

If i am not wrong about this, i believe to achieve that with JavaScript it will require some kind of server stream to allow the browser to download the pdf file. However, they did add a download keyword to the new HTML5. I have provided a link below you can check how to use this. I am sorry if I did not fully answer your question though, but I hope this link can help.

https://www.w3schools.com/howto/howto_html_download_link.asp