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

Juneau Lim
Juneau Lim
13,362 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,157 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,193 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
13,362 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.