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

Otec Perez Glass
Otec Perez Glass
7,678 Points

My solution!

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



// Lets add an attribute to all the secure $secureLinks
$secureLinks.attr("target", "_blanck");
$pdf.attr("target", "_blanck");

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


$pdf.on('click',(e)=> {

  if ($(':checked').length === 0){
    e.preventDefault();
    alert(' Yo Check The checkbox');
  }

});


//unobtrusive
const ul = $('ul');
const label =  $('<label></label>');
const checkbox = $('<input>');
checkbox.attr('type', 'checkbox');
label.text('Allow PDF downloads '); 

label.append(checkbox);
ul.append(label);

1 Answer

Hi Otec Perez Glass I found a small mistype in the code where you add the attributes to $secureLinks and $pdfs

Your Code:

$secureLinks.attr("target", "_blanck");
$pdf.attr("target", "_blanck");

Updated Code:

$secureLinks.attr("target", "_blank");
$pdf.attr("target", "_blank");