Bummer! This is just a preview. You need to be signed in with a Treehouse account to view the entire video.
Using jQuery to Manipulate Elements and Add Behavior1:09 with Andrew Chalkley
Now that you know how to select elements, the next step is adding behavior and interactivity.
Now that you can select elements, it is time to manipulate them or add behavior.
To do this, we add the name of the method we want to call.
For example, if you want to hide a page element,
you'd want to use the hide method.
Some methods take arguments, for example, the before method.
It takes a string of HTML and adds it before the selected element.
This would add the first level header with the word "hello"
before the element called, "myElement."
Other methods take functions as arguments
to be run when an event happens, like a click.
These are known as handlers.
You can write a handler using an anonymous function,
which is written, "function," a pair of parentheses, and a pair of curly braces.
The code you want executed is placed
between the opening and closing curly braces.
Methods can be chained together to save lines of code
and improve readability, like this.
Are you ready for for a quiz and a code challenge?
You are? Good! Because that's what's coming up next!
You need to sign up for Treehouse in order to download course files.Sign up