Book Image

jQuery Essentials

By : Troy Miles
Book Image

jQuery Essentials

By: Troy Miles

Overview of this book

<p>JQuery is still the most popular JavaScript library. It is used in over 60% of the top websites on the Internet. It was written to make DOM manipulation (so, moving things around a web page) easier for developers. It acts through JavaScript to ascribe HTML elements to the DOM attributes. Because it is a library of predefined functions, all you need to start using jQuery is a working knowledge of the syntax and a reference for the functions available to you.</p> <p>This practical guide shows you how to make the most of jQuery to boost the performance of your websites and applications. We start off with a quick glance through the basics of JQuery, followed by the explanation of JQuery selectors, filters, and DOM element manipulation. After this, you will learn how events and animations can be used to create and design beautiful and user-friendly sites. Next, you will be familiarized with Ajax functions to help you send and receive data from your server. Finally, we’ll walk you through using built-in plugins and eventually create your own plugins for your websites.</p> <p>By the end of this book, you will be able to to build robust and efficient websites successfully using JQuery.</p>
Table of Contents (17 chapters)
jQuery Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Enabling and disabling elements


Elements in your form that are not valid should be disabled. A disabled element is usually shown dimmed-out with gray text. A disabled element can't be focused, doesn't respond to the user, and won't be sent when the form is submitted.

The odd thing about the disabled attribute is that its presence inside of an element disables it. It doesn't need to be set to true or false. In fact, setting it true or false has no effect. To disable the element, add the disabled attribute. To enable the element, remove the disabled attribute. Luckily, jQuery understands this odd behavior and takes care of this detail for us.

We can use the jQuery .prop() method to help us out. When we want to disable the element, we do the following:

$('#someId).prop('disabled', true);

And when we want to enable the element, we do the following:

$('#someId).prop('disabled', false);

In spite of the way things look, jQuery will do exactly what we said. The first line of code will add the disabled...