Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
jQuery for Designers Beginner's Guide Second Edition

You're reading from   jQuery for Designers Beginner's Guide Second Edition Design interactive websites to improve user experience by using the popular JavaScript library

Arrow left icon
Product type Paperback
Published in Jul 2014
Publisher
ISBN-13 9781783284535
Length 398 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Natalie Maclees Natalie Maclees
Author Profile Icon Natalie Maclees
Natalie Maclees
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Designer, Meet jQuery FREE CHAPTER 2. Enhancing Links 3. Making a Better FAQ Page 4. Building an Interactive Navigation Menu 5. Showing Content in Lightboxes 6. Creating Slideshows and Sliders 7. Working with Responsive Designs 8. Getting the Most from Images 9. Improving Typography 10. Displaying Data Beautifully 11. Reacting to Scrolling 12. Improving Forms A. Pop Quiz Answers Index

Time for action – getting ready for jQuery

Perform the following steps to start with your first jQuery script:

  1. Set up your files and folders just like we did in the previous exercise. Inside the <body> tags of the HTML document, add a heading and a paragraph, as follows:
    <body>
    <div class="content">
      <h1>My First jQuery</h1>
      <p>Thanks to jQuery doing fancy JavaScript stuff is easy.</p>
    </div>
    </body>

    Feel free to add some CSS code to the styles.css file in the styles folder. Style this however you'd like.

  2. Next, open up that empty scripts.js file we created earlier and add this bit of script to the file:
    $(document).ready();

What just happened?

Let's take this statement one thing at a time—first, the dollar sign. Really? What's this doing in JavaScript?

The $ here is just a variable—that's all. It's a container for the jQuery function. Remember how I said we might use a variable to save ourselves a few keystrokes? The clever writers of jQuery have provided the $ variable to save us from having to write out jQuery every time we want to use it. The following code does the same thing that the preceding script did:

jQuery(document).ready();

Except that it takes longer to type. jQuery uses the $ sign as its short name because it's unlikely that you'd call a variable $ on your own as it's an uncommon character. Using an uncommon character reduces the chance that there will be some sort of conflict between some other JavaScript being used on a page and the jQuery library.

So, in this case, we're passing document to the jQuery (or $) function because we want to select our HTML document as the target of our code. When we call the jQuery function, we get a jQuery object. In JavaScript, we'd say that the jQuery function returns a jQuery object. The jQuery object is what gives the jQuery library its power. The entire jQuery library exists to give the jQuery object lots of properties and methods that make our lives easier. We don't have to deal with lots of different sorts of objects; we just have to deal with the jQuery object.

The jQuery object has a method called ready. In this case, the ready method will be called when the document is loaded into the browser and is ready for us to work with. We can pass a function to the ready method to say what should happen. So $(document).ready() just indicates when the document is ready.

You have been reading a chapter from
jQuery for Designers Beginner's Guide Second Edition
Published in: Jul 2014
Publisher:
ISBN-13: 9781783284535
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image