Category: Working with properties, attributes, and data
-
Conclusion
In this lesson we’ve gone beyond the art of selecting elements and started manipulating their attributes and properties. In these pages you discovered the differences between attributes and properties and how you can operate on them using jQuery. In addition, you learned how to perform basic tasks—for example, forcing external links to be opened in…
-
Storing custom data on elements
Let’s just come right out and say it: global variables suck. Except for the infrequent, truly global values, it’s hard to imagine a worse place to store information that you’ll need while defining and implementing the complex behavior of your pages. Not only do you run into scope issues, but they also don’t scale well…
-
Manipulating element properties
As with the attr() method, to get and set a value of a property in jQuery you can use a similar approach: the prop() method. attr() and prop() are similar in their capabilities and in the parameters they accept. Besides, for those of you who like anecdotes, the prop() method was extracted from attr() as a way to reorganize the latter and to let it focus solely…
-
Removing attributes
In order to remove attributes from DOM elements, jQuery provides the removeAttr() method. Its syntax is as follows. Method syntax: removeAttr removeAttr(name) Removes the specified attribute or attributes from every matched element Parameters name (String) The name of the attribute or list of attributes’ names separated by a space to remove Returns The jQuery collection Let’s see…
-
Working with attributes
In this section we’ll delve into the world of attributes and the methods jQuery offers to work with them. Fetching attribute values In jQuery, to get and set a value of an attribute you can use the attr() method. This is a typical peculiarity of jQuery. As you’ll often see, the same method can be used either…
-
Defining element properties and attributes
When it comes to DOM elements, some of the most basic components you can manipulate are the properties and the attributes assigned to those elements. These properties and attributes are initially assigned to the JavaScript object instances that represent the DOM elements as a result of parsing the HTML markup, and they can be changed…
-
Working with properties, attributes, and data
This lesson covers Everyone who has approached software development for the first time has learned a very important lesson: even huge and complex software consists of a mix of elementary instructions. Summing numbers, counting items, and iterating over elements are just a few examples of these basic operations. In the same way, you can create…