JavaScript jQuery Basics Working with jQuery Collections Changing Element Properties

Juneau Lim
Juneau Lim
11,213 Points

target _blank & download not working

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

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

Have no idea why. :-( I'm using chrome and cleared cash.

Robin Siegl
Robin Siegl
11,155 Points

So i tested this course and got the same error with the download property, but the target _blank does work for me.
I also logged the the variables to the console to see if it assigns the right attributes (it does).
My Code:

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

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

// Log to console
console.log($secureLinks);
console.log($pdfs);

1 Answer

Kristaps Vecvagars
Kristaps Vecvagars
6,185 Points

Changing settings in Chrome activated the download feature, however, it seems the download attribute has no bearing on the behavior, at least for .pdf files. Is this true or not?

Juneau Lim
Juneau Lim
11,213 Points

Thank you very much for your kind answer Kristaps. I'll try it as soon as I got a bit sane. I'm out of my mind right now due to the start of the new semester. But your advice definitely sounds promising. I really appreciate your kindness.

Katiuska A
Katiuska A
8,991 Points

Thank you! Which settings, exactly?