JavaScript jQuery Basics Working with jQuery Collections Changing Element Properties

Hanane Ladj
seal-mask
.a{fill-rule:evenodd;}techdegree
Hanane Ladj
Front End Web Development Techdegree Student 9,185 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
Hanane Ladj
Front End Web Development Techdegree Student 9,185 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