Module 6 - Lesson 9

jQuery Variables

In this short lesson, I’d like to explain what variables are and how we can use them when writing our jQuery code.

Video Chapters

00:00 Introduction

00:30 Creating a variable

01:42 Alerting a variable

03:40 Storing selectors as variables

07:23 Global and local variables

Code Examples

// Example 1 	

var sampleVar = "Hello!";

alert(sampleVar);

// Example 2 - number

var One = 1;
var Two = 2;

alert(One + Two); // 3

// Example 3 - text string

var One = "1";
var Two = "2";

alert(One + Two); // 12

// Example 4

var $paragraph = $('p');

$paragraph.text('this is new');
$paragraph.text(sampleVar);

Join the discussion

Share your thoughts about this lesson with fellow students!

Login to your Account

If you're a DSA Student, please log in to your account to access the course content.

Sorry, you don't have access to this content.

It looks like you're not enrolled in Divi Stylist Academy.