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 1

Tawny Bartlett
Tawny Bartlett
24,674 Points

event.preventDefault() doesn't work in my browsers?

Hi there, I hope someone can help me. I have this code:

$("#imageGallery a").click(function(event){
  event.preventDefault();
  var href = $(this).attr("href");
  //1.1 Show the overlay
  //1.2 Update overlay with the image linked in link
  //1.3 Get child's alt attribute and set caption
});

And I know it SHOULD work because I passed the Challenge, but I don't understand , Firefox and Chrome both still use the a href link as default and go through to the image.

I've installed a Jquery plugin for Firefox but still no luck...

2 Answers

Dave McFarland
STAFF
Dave McFarland
Treehouse Teacher

HI Tawny Bartlett

Have you checked the JavaScript console for any syntax errors? In Chrome you can open the JavaScript console with Ctrl-Shift-J (windows) or Cmd-Option-J (Macs). Open the console and reload the page -- do you see any errors listed? A syntax error will prevent your programming from running, so the preventDefault() method won't work either.

Tawny Bartlett
Tawny Bartlett
24,674 Points

Hmm... It's working now... I have no idea what happened unfortunately, I can't see any errors or warnings now! I did the next step in the project and it's suddenly started working?!

Hmm.. thank you for the advice though, I will look for errors and warnings next time. :)