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 Stopping the Browser's Default Behavior

my alert box won't come up and I lost my check box option completely

its obvious I did something wrong but it won't come up in the console

<!DOCTYPE html> <html> <head> <title>jQuery Weekly</title> <link rel="stylesheet" href="css/style.css" type="text/css" media="screen" title="no title" charset="utf-8"> </head> <body> <div class="box"> <h1>jQuery Weekly</h1> <div id="links"> <ul> <li><a href='https://learn.jquery.com/'>Learn jQuery</a></li> <li><a href='http://treehouse-project-downloads.s3.amazonaws.com/jquery-basics/jquery_cheatsheet.pdf'>jQuery Cheatsheet</a></li> <li><a href='https://api.jquery.com/'>jQuery Documentation</a></li> <li><a href='https://developer.mozilla.org/en-US/docs/Glossary/jQuery'>jQuery Glossary</a></li> </ul>

</div>

</div> <script src="js/jquery-3.2.1.min.js"></script> <script src="js/app.js"></script> </body> </html>

const $odd = $('a:odd'); const $secureLinks = $('a[href^="https://"]'); const $pdfs = $('a[href$=".pdf"]'); const $pdfCheckbox = $('<label><input type="checkbox"> Allow PDF downloads</label>');

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

$secureLinks.addClass('secure'); $pdfs.addClass('pdf');

$pdfs.on('click', function(event){ if ($(':checked').length)===0){ event.preventDefault(); alert('please check the box to allow pdf downloads.'); } });

$('#links').append($pdfCheckbox);

('a').each(function(index, element){ console.log(index, $(element).attr('href')); });

Timo Koskinen
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Timo Koskinen
Full Stack JavaScript Techdegree Graduate 24,972 Points

Hello James!

There's a small typo: if ($(':checked').length) === 0) {

should be: if ($(':checked').length === 0) {

If you use an editor like Visual Studio Code, you would see this error while you type. I make a lot of typos myself so it's a must feature for coding to me, you should test if it makes coding more easy to you too.

1 Answer

I use to use Visual Studio Code but I was always having problems with having the right version for the situation and I am always having problems downloading everything to it. when following along with treehouse this is what would happen