10 jQuery Tips and Tricks for Visual Studio | 2 | WebReference

10 jQuery Tips and Tricks for Visual Studio | 2


10 jQuery Tips and Tricks for Visual Studio [con't]

6. Find Hidden Elements Using jQuery

You can use the Size() method to determine whether any DOM elements are hidden. Here is an example:

You can achieve the same result using the length() function as well. Note that the Size() function uses the Length() function internally. Hence, it works faster.

7. Saving Data in DOM

You can use the Data() function to store data in a DOM element. The following code snippet shows how you can set a value to a DOM element in jQuery:

To retrieve the value stored in a DOM element, you can use the following code:

8. Retrieve the Parent Element of an Element

It is easy to retrieve the parent element of an element in jQuery. All you have to do is use the closest() method as shown below:

9. Use Chaining in jQuery Properly

Chaining is a great jQuery feature. It facilitates a list of actions that are executed one after the other. You can use it to chain methods, as shown in the code snippet below:

10. Manipulating Select List with jQuery

JQuery makes working with a Select List easy. You can easily remove an option from a Select List. Here's how:

The following code snippet illustrates how you can retrieve the selected option from a Select List as text:


This article presented 10 helpful tips and techniques for getting the most from JQuery, the powerful JavaScript library for simple cross-browser, client-side scripting, event handling, animations, DOM traversal, Ajax development, and more.

Original: October 25, 2010