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
john larson
16,594 PointsHas anyone noticed... preventDefault() works without passing in the parameter in this case?
$(document).ready(function(){
$("a").click(function(event){//andrew shows us this way
event.preventDefault();
});
});
$(document).ready(function(){
$("a").click(function(){//but this seems to work as well
event.preventDefault();
});
});
3 Answers
Thomas Nilsen
14,957 PointsI'm not using jQuery on a regular basis, but the point is you get 2 different objects back (depending on if event is passed to the function or not). In your case you can access the preventDefault() method either way, so it doesn't matter.
Thomas Nilsen
14,957 PointsIt's not the same, but in this case it doesn't matter.
Check out this fiddle
Run it and open your console to see the difference.
john larson
16,594 PointsI ran it, looked at the console...but I don't know what I'm looking at. I guess you're saying in other or most circumstances we need to pass a parameter or something bad will happen.