In past episodes, we talked about caching a collection of elements to avoid multiple returns to the DOM to fetch the elements. Let’s talk about it now in the context of the script you are writing. You’ll see an additional “why” of caching.
The variable $ does not have context and does not natively mean jQuery. It can also stand for Mootools and any value. You need to specifically initialize jQuery to the $ variable. Let’s talk about it in relationship to the IIFE. I’ll show you how to pass jQuery into the IIFE (yes, you can pass in objects) and then assign it to the variable for use within the IIFE’s scope.
IIFE stands for Immediately Invoked Function Expression and is pronounced as “iffy.” Let’s talk about what it is, why and when you want to use it, and then how to write it. You’ll learn about scope too.
Let’s get out of the browser’s console and write your first script. In this episode, you will simply create a script file and then learn how to load that file into the DOM through WordPress. Yes, you will learn about enqueuing script files using the WordPress event wp_enqueue_scripts and its function wp_enqueue_script. Psst…if you need to learn about WordPress’ event-driven engine (you know that thing in Core that handles hooks/filters), go take this hands-on lab. Get the Sandbox Plugin
I bet you’d like to animate an element to increase the front-end interactive. In this episode, you will work with various jQuery effect commands including: hide() show() slideUp() slideDown() You’ll see how to change the duration, which changes the speed of the effect.