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

Why are we preventing the "normal" browser response when clicking on an image vs. just stopping the response?

$("#imageGallery a").click(function(event){

I just watched Andrew's Perform Part 1 jQuery video, but I'm not understanding why we're preventing the browser's default reaction to clicking on an image (which opens a "dead end" link) vs. just changing/stopping the response to clicking on an image to begin with.

The preventDefault event feels to me like you're trying to stop a boulder from completely rolling down the hill by lassoing it mid-downhill roll (which something silly and impractical...which is what I'm currently seeing event.preventDefault() as) vs. just preventing the boulder from rolling down the hill in the first place. So why the heck are we using event.preventDefault?

Simon Coates
Simon Coates
28,694 Points

Unsure what you're proposing in terms of stopping the behavior. The default navigate away tends to be when using a form or anchor. You typically want that default behavior to remain intact for when javascript is disabled, but when enabled want javascript to stop it (lasso it) and do something else (throw up an overlay, run some ajax).