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 (2014) Creating a Simple Lightbox Perform: Part 2

Alleene Lacaba
PLUS
Alleene Lacaba
Courses Plus Student 5,248 Points

click event

Capture the click event on a link to an image is not working... I'm doing my own version but I'm copying what Andrew wrote, and failed to wrok in my version.

here's my code: <ul class="tabs"> <li><a href="#A_list" tabindex="1">A</a></li> <li><a href="#B_list" tabindex="2">B</a></li> <li><a href="#C_list" tabindex="3">C</a></li> <li><a href="#D_list" tabindex="4">D</a></li>

and here's the javascript:

$(".tabs li a").click(function(event){
  event.preventDefault();
  var href = $(this).attr("href");
  console.log(href);
});

EDIT: I added in proper way to highlight your code. Press EDIT if you want to see what i did to achieve this effect -Aurelian

2 Answers

Stefan Osorio
Stefan Osorio
16,419 Points

Just tested your code, works perfectly fine. I suppose there's a problem with your selector (".tabs li a"). Is the shown html really wrapped in something with a class of "tabs"?

Alleene Lacaba
Alleene Lacaba
Courses Plus Student 5,248 Points

you're right, there's something wrong! thanks much

Cesar Vanbuskirk
Cesar Vanbuskirk
6,672 Points

Try putting the image in the href="" instead of #A_list. So href="img/example.jpg".