jQuery Tutorial #2 - Event Binding - jQuery Tutorial for Beginners
Key Takeaways
This video tutorial covers event binding in jQuery, demonstrating how to listen to user interactions and perform actions on HTML elements, including clicking, hovering, and toggling visibility.
Full Transcript
okay so jQuery lesson number two if you missed lesson number one I'm going to put the link in the description you're definitely going to want to see that I'm also going to get a link on the screen here you should see that if you're not on mobile let's move forward so in the last lesson I showed you how to do jQuery actions um or methods as they're called uh one I didn't show you is the HTML method so if I go btn1 let's get grab button one I can do HTML and I can actually change what's in the HTML code so right now the code is just that button one text so now it's called my button that's kind of fun so what I actually got to do is I got to rewrite what's inside of that HTML element let's look at panel one here that's this guy this div um and what I get to do here is I can actually rewrite the entire inside of it so I can go if I do panel one HTML my panel so there you go all the elements are gone that were inside and now the only thing inside of it is text that says my panel I can even add new tags bold not bolts this isn't too good of an idea to do very much of but you can do a little bit you can add a tag or two and it's not considered a bad practice okay so we know how to do jQuery methods so let's listen to what the user doing and do methods when the user interacts with our page so we're going to do is let's give an example when we click on button one I want this panel to show and hide so let's go button one we start with the thing we're wanting to listen to and the method is called on and then we give it a event name this is a JavaScript event name so I'm going to go on click the first these are called arguments that I'm passing here the first thing I'm giving it is listen to The Click event and then I'm going to go comma and then I'm going to give it my function which you'll recognize from up here open close parenthesis open close curly braces so anything in between those curly braces now will fire whenever the click event takes place so now I can go I'm going to add the pr seed or the semicolon to be a good guy now I can go panel one hide actually I'll just go toggle that way it'll show and hide Whatever It Isn't So when I click on button one it's going to run this function and it's going to toggle panel hey would you check that out let's actually make that slide toggle this is something you use probably I'll make it a slide toggle of 200 there you go slides and is beautiful let's make it when I click on the panel I actually want it to hide that panel itself so when you click on panel one there you go it's gone now I can't actually click it to toggle it back so I have to hit the button to well I took away my button one now didn't I so I can't actually bring it back without refreshing my page um but that's how you would do that if you want to get rid of things I could make an x button inside of here so when you click that x button it tells panel one to go away so I can actually make it fade out that might make a little more sense click and it's gone and that's a lovely way of doing things you'll notice I changed the panel I didn't remove the whole column which is why those things are sitting there so um let's go into a little bit more clever usage of this so let's say we had button one let's assign these buttons to each one of these panels btn1 I think is what they're called btn1 panel one Fade Out There we go I'm going to go button two you're going to do panel two I'm going to do button three does panel three and button four does panel four there you go so now each one of these should go away go away go away go away come back all right did I just do Fade Out yep let's do Fade toggle do my Nifty Sublime Text multiple cursors there there you go any order now I actually have a pretty living breathing page nice let's actually change this event from click to Mouse over something you might want to do sometimes and it's going to going toggle them each time now I get to do some fun crazy you know everybody's got to do that when they make something like that right so there you go and mouse over I can make it to where all it does is Fade Out and you have to click to bring it back in Mouse over it's going to fade out I'm going to copy and paste all of these you notice it's pretty easy to get a mess of jQuery in the next video I'm going to show you how to clean this up cuz this is already kind of too much we don't really want to do it this way um and so then when I click I'm going to tell it to fade back in so now I have four mouseovers on Mouse over we're going to fade out and when we click we're going to fade back in Fade Out Fade Out Fade Out click will bring me back in there we go that's a super fun way of doing things uh what I can also do is I'll teach you one more method here so let's go on click function on button one click panel one we are actually going to go find and now we get to look inside of panel one what I want to do is panel one body panel body this is what I want to change here I'll go panel actually I won't do find I'll just go panel one panel body and I'm going to change that HTML to my new panel content so now I click on that my panel content will change to my new panel content nice very good so that is pretty much how you listen to events and then tell your page to do stuff one cool thing you could do is I could have all these panels hidden by default which I could do you know with a CSS class um or in this case I'll just make it I'll do it the wrong way here and go display none so now all these panels are going to be hidden by default and then the button will activate them and you'll get to show them so button one on click panel one. show ah what's going toggle so on button one click panel one will toggle so they're all hidden there you go and now I can copy and paste that to button two if you're using Sublime Text by the way Apple D is what gives you multiple cursors like that there you go so now they're all going to toggle whenever I hit these so that's kind of your intro to listening to jQuery events the next video we're going to show you how to clean up your jQuery cuz there's no way you actually need to do this when they all do the exact same thing I'm going to show you how to clean that up how to reuse some stuff in jQuery and just how to make it a little bit more professional so catch that video next and have a good day
Original Description
This second part of the jQuery Tutorial for beginners will show you how to do event binding with jQuery. Events happen whenever a user clicks, hovers, drags, types, or does pretty much anything to interact with an HTML element.
jQuery allows the web developer to easily write a program to listen to these javavscript events and modify the webpage in realtime. This is often called a dynamic website.
You can do all of this in plain javascript, but jQuery makes it incredibly easier.
Previous Lesson - #1: https://www.youtube.com/watch?v=hMxGhHNOkCU&list=UUVTlvUkGslCV_h-nSAId8Sw
Next Lesson - #3: https://www.youtube.com/watch?v=Cc3K2jDdKTo&list=UUVTlvUkGslCV_h-nSAId8Sw
-~-~~-~~~-~~-~-
Also watch: "Responsive Design Tutorial - Tips for making web sites look great on any device"
https://www.youtube.com/watch?v=fgOO9YUFlGI
-~-~~-~~~-~~-~-
Playlist
Uploads from LearnCode.academy · LearnCode.academy · 20 of 60
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
▶
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Web Development Tutorial for Beginners (#1) - How to build webpages with HTML, CSS, Javascript
LearnCode.academy
Web Development Tutorial for Beginners (#2) - Basic CSS - How to build a website with HTML & CSS
LearnCode.academy
How to create CSS Layouts - Web Development Tutorial for Beginners (#3) - with HTML & CSS
LearnCode.academy
Bootstrap Tutorial For Beginners - Responsive Design with Bootstrap 3 - Responsive HTML, CSS
LearnCode.academy
Angularjs Tutorial for Beginners - learn Angular.js using UI-Router
LearnCode.academy
CSS Tutorial - Web Development Tutorial for Beginners (#5)
LearnCode.academy
Node.js tutorial for beginners - an introduction to Node.js with Express.js
LearnCode.academy
Github Tutorial For Beginners - Github Basics for Mac or Windows & Source Control Basics
LearnCode.academy
Javascript Tutorial - Programming Tutorial for Beginners Pt 1
LearnCode.academy
Javascript Tutorial - jQuery Tutorial for Beginners Pt 2
LearnCode.academy
AngularJS Directives Tutorial - Part 1 - Demystifying Angular Directives
LearnCode.academy
WATCH THIS IF YOU WANT TO BECOME A WEB DEVELOPER! - Web Development Career advice
LearnCode.academy
YEOMAN TUTORIAL - Master Front-End Workflow with Yeoman, Grunt and Bower
LearnCode.academy
BOWER! - Streamline Web Workflow with Bower Package Manager
LearnCode.academy
Chrome DevTools for CSS - Better CSS Coding & CSS Debugging with Developer Tools
LearnCode.academy
GITHUB ATOM - Why Atom.io will be your favorite Text Editor!
LearnCode.academy
GITHUB PULL REQUEST, Branching, Merging & Team Workflow
LearnCode.academy
Pimp that Terminal - Add shortcuts and functions to your .bash_profile to simplify routine tasks
LearnCode.academy
jQuery Tutorial #3 - Writing Smarter, Better Code - jQuery Tutorial for Beginners
LearnCode.academy
jQuery Tutorial #2 - Event Binding - jQuery Tutorial for Beginners
LearnCode.academy
jQuery Tutorial #1 - jQuery Tutorial for Beginners
LearnCode.academy
Node.js MongoDB Tutorial using Mongoose
LearnCode.academy
Node.js tutorial for beginners 2014 - an introduction to Node.js with Express.js
LearnCode.academy
WEB DEVELOPMENT - SECRETS TO STARTING A CAREER in the Web Development Industry
LearnCode.academy
jQuery Tutorial #4 - DOM Traversal with jQuery
LearnCode.academy
jQuery Tutorial #5 - Building a jQuery Tab Panel Widget
LearnCode.academy
jQuery Tutorial #6 - Building a jQuery Image Slider
LearnCode.academy
jQuery Ajax Tutorial #1 - Using AJAX & API's (jQuery Tutorial #7)
LearnCode.academy
jQuery Ajax Tutorial #2 - Posting data to backend (jQuery tutorial #8)
LearnCode.academy
jQuery Ajax Tutorial #3 - Delegating Events & Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
jQuery Ajax Tutorial #4 - "Edit" modes & Better Mustache.js Templating (jQuery tutorial #9)
LearnCode.academy
How to put your website online - how to FTP to a domain & upload files to a webhost
LearnCode.academy
Basic Terminal Usage - Cheat Sheet to make the command line EASY
LearnCode.academy
SSH Tutorial - Basic server administration with SSH
LearnCode.academy
Vagrant Tutorial - Running a VM For Your Local Development Environment
LearnCode.academy
Sublime Text Favorite Packages and Workflow
LearnCode.academy
What Makes Javascript Weird...and AWESOME - Pt 1
LearnCode.academy
Javascript is Event-Driven - What makes Javascript Weird...and Awesome Pt 2
LearnCode.academy
Javascript Closures Tutorial - What makes Javascript Weird...and Awesome Pt 3
LearnCode.academy
FREE REST API - Practice Developing Javascript AJAX Apps with this API
LearnCode.academy
Javascript Scope Tutorial - What Makes Javascript Weird...and Awesome Pt 4
LearnCode.academy
Javascript Context Tutorial - What makes Javascript Weird...and Awesome Pt5
LearnCode.academy
Nginx Tutorial - Proxy to Express Application, Load Balancer, Static Cache Files
LearnCode.academy
Live Reload Sublime, Chrome, Anything - Fast and easy with Live-Server
LearnCode.academy
Are you bad, good, better or best with Async JS? JS Tutorial: Callbacks, Promises, Generators
LearnCode.academy
Javascript Generators - THEY CHANGE EVERYTHING - ES6 Generators Harmony Generators
LearnCode.academy
Web Development Advice - Interview with Dev Tips
LearnCode.academy
How the Internet Works for Developers - Pt 2 - Servers & Scaling
LearnCode.academy
How the Internet Works for Developers - Pt 1 - Overview & Frontend
LearnCode.academy
HAPROXY vs NGINX - 10,000 requests while killing servers
LearnCode.academy
Node.js Cluster - Boost Node App Performance & Stability with Clustering
LearnCode.academy
Web Dev Training with Treehouse
LearnCode.academy
What is Node.js Exactly? - a beginners introduction to Nodejs
LearnCode.academy
How to deploy node.js applications #1 - spin up a server
LearnCode.academy
Deploying node.js applications #2 - provision server & setup flightplan
LearnCode.academy
Deploying Node.js Applications - Deploy Node the right way - as an Upstart Service
LearnCode.academy
Mobile Web Design - Coding Workflow For Mobile Websites
LearnCode.academy
WHY YOU NEED A BUILD SYSTEM LIKE GRUNT, GULP, BRUNCH FOR YOUR WEBSITE
LearnCode.academy
GRUNT TUTORIAL - Grunt makes your web development better!
LearnCode.academy
STOP USING FTP! - How to Deploy with Flightplan over SSH
LearnCode.academy
More on: JavaScript Fundamentals
View skill →Related Reads
🎓
Tutor Explanation
DeepCamp AI