diff --git a/page/using-jquery-core/attributes.md b/page/using-jquery-core/attributes.md index af75f0c4..4460b63d 100644 --- a/page/using-jquery-core/attributes.md +++ b/page/using-jquery-core/attributes.md @@ -1,28 +1,30 @@ --- -title : Attributes +title : Properties level : beginner --- An element's attributes can contain useful information for your application, so it's important to be able to get and set them. -## `$.fn.attr` +## `$.fn.prop` -The `$.fn.attr` method acts as both a getter and a setter. As a setter, `$.fn.attr` can accept either a key and a value, or an object containing one or more key/value pairs. +The `$.fn.prop` method acts as both a getter and a setter. As a setter, `$.fn.prop` can accept either a key and a value, or an object containing one or more key/value pairs. -`$.fn.attr` as a setter: +`$.fn.prop` as a setter: ``` // Setting attributes -$("a").attr( "href", "allMyHrefsAreTheSameNow.html" ); +$("a").prop( "href", "allMyHrefsAreTheSameNow.html" ); -$("a").attr({ +$("a").prop({ title: "all titles are the same too!", href: "somethingNew.html" }); ``` -`$.fn.attr` as a getter: +`$.fn.prop` as a getter: ``` // Getting attributes -$("a").attr("href"); // returns the href for the first a element in the document +$("a").prop("href"); // returns the href for the first a element in the document ``` + +`$.fn.attr` is similar `$.fn.prop` to but is rarely needed. The first is supposed to be used with the original (source code) attributes while the second manipulates the computed DOM tree properties.