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

preventDefault not working using workspace. I have the corerct syntax is their some issue with Chrome?

preventDefault not working using workspace. I have the corerct syntax is their some issue with Chrome?

var $overlay = $('<div id="overlay"><div>');
$("body").append($overlay);
$("#imageGallery a").click(function(event){
  event.preventDefault();
  var href = $(this).attr("href");
  $overlay.show();
});```

1 Answer

geoffrey
geoffrey
28,736 Points

Your code looks valid to me, I've even just tested it, and that works fine, that should as well works correctly inside your workspace.

Have you checked the console ? Just to see if there is an error or something else that might explain it ? Also, you ask if there is any particular issue with Chrome, I don't think so, I went through this tutorial using chrome without any problem, but you can still check with another browser.