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

HTML jQuery Basics (2014) Creating a Simple Lightbox Perform: Part 1

David Taber
PLUS
David Taber
Courses Plus Student 3,574 Points

Confused on how "default behavior" works in jQuery

Concerning the behavior of the webpage for console.log. How did you recognize the default behavior is what needed to be that it was the default behavior that needed to be changed? And what tokens default behavior in particular. The click event?, Console.log? Both? This is unclear.

3 Answers

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I'm confused by the question...but I will try. In normal circumstances, when you click a link, it takes you to another page - local or external. This is DEFAULT behavior. In this video we want to prevent that behavior and make it do something else - show an overlay within the current HTML structure. Console.log is mostly used for checking what is happening by printing things out in the browser's js console.

David Taber
PLUS
David Taber
Courses Plus Student 3,574 Points

Simply he was able to recognize the default behavior of some method, click was the cause. How did he arrive at this conclusion?.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

With links (the <a> elements) it's pretty obvious, so no need for special conclusions here. This is HTML 101 - hyperlinks take you to other pages and that is why they require the href attribute, I can't imagine any other default behavior for clicking links. In other cases you just click and try, then prevent default and see what happens when you do. Programming consists of a lot situations like this - you either know something already or you experiment in various ways.

David Taber
PLUS
David Taber
Courses Plus Student 3,574 Points

There is no logical path that would lead you to that conclusion outside of knowing about .preventDefault() method with foreknowledge. Outside of trial and error--through the documentation maybe, which is what you are suggesting.

Absolutely nothing happened in the previous step (when the output was written to console.log) being new to chrome a number of possibilities enters the mind.

Please refer yourself to the video part 1 time index 5:00 onward. He clicks on the link and it does what it supposed to do. Then he said something flashed? Console.log? why in the world wouldn't the text just stay there from console.log. This leads someone to the very reasonable conclusion that it was a chrome issue. Why wasn't anything written to console.log? Is the code typed incorrectly? Is it chrome? What I am saying is the instructor just dismisses the behavior and then concludes that it is the default behavior of something.

My first guess is that it would be Chrome.

If I got those instructions off the net somewhere (up to the point of him actually informing you that it was the default behavior related to the Anchor element) I would have no clue, really ask yourself the question. The value existed for the variable why wouldn't it show up in chromes console anyway? That makes no sense.

And you don't arrive that it is a case of "a" element because the link works!!! it does what it is supposed to do. A=A I get that!

There simply needed to be more of an explanation on how he was able to recognize that. Furthermore a quick two sentence mention about the reason the output to the console was not persistent would have been welcome.

Additionally there is another ambiguous part in part 4 where he appends DOM objects, turns out doesn't really matter the order at least in Aptana. There is another in part two where he has a variable called href, coming from a background in strongly typed languages like C++ and C# this would be like naming a variable O or Int, bad programming practice. It absolutely blew my mind when he said that the convention of people that name JQuery objects with "$" appended at the front of the variable name. From my background this is surprising. Are you calling a JQuery method or are you defining a variable?

Mr Chalkley does no a nice job of developing the approach to solving a problem as well as how to navigate the documentation.

I will say that I get the overall methodology of introducing simple concepts then developing those concepts later, it works. I would just like more explanation sometimes to fill in the gaps.