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

Is preventDefault() method deprecated?

As of Sept. 8, 2016 http://api.jquery.com/category/events/browser-events/ shows only 3 methods, none of which are preventDefault().

Is the method deprecated, and if so, what is a suitable replacement to test a console.log() view of $(this).attr("href") ? Below is my JavaScript in case my syntax is incorrect.

// 1. Capture click event when user clicks on link to an image $("#image-gallary a").click(function(event){ event.preventDefault(); var href = $(this).attr("href"); console.log(href);

// 1.1, Show the overlay // 1.2, Update overlay with the linked to image // 1.3, Add alt attribute of the image to the overlay (get childs alt text and display it as a caption)

2 Answers

Thank you! That was driving me nuts :)

Sergey Blokhin
Sergey Blokhin
9,612 Points

event.preventDefault(); Is not working, please what s the problem?

<ul > <a id="bibi" href="images/boat.png"><img src="images/boat.png"></a> </ul>

<script> $("#bibi").click(function(event){

event.PreventDefault(); var href = $(this).attr("href"); console.log(href); }); </script>