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
Jack Hou
6,975 PointsjQuery syntax question
The deep dive on jQuery doesn't really go over how the syntax works in jQuery. The teacher kinda just type the code along and describe what the code does instead of mentioning why we're positioning this way.
$(#form span).hide() $("input").focus(function(){
$(this).next().fadeIn("slow");
}).blur(function(){
$(this).next().fadeOut("slow");
}).keyup(function(){
// some code here
})
Can someone explain the above code to me? I understand what it does in a webpage, but why are .blur() after .focus(), and .keyup() after .blur? are all the methods targeting $("input")? and what is keyup() and next()? I tried looking it up on jQuery website but am still confused.
Sorry for a barrage of questions
1 Answer
Matthew Jay
14,625 PointsWhen the user moves out of the selected form field or input (blur) select the immediate sibling element (this.next) and fade it out at a rate of 600ms.
Here's an example: http://codepen.io/anon/pen/arhKp
Keyup is called on when you release a key on the keyboard. If you were to replace "//some code here" with:
alert("Boo!");
Every time someone typed a letter into the input an alert would popup. Which is hilarious of course.