From f5b2a3e5fc93324091e6d6dd07ec45237a5fffd6 Mon Sep 17 00:00:00 2001 From: lsoares Date: Mon, 18 Feb 2013 19:11:49 +0000 Subject: [PATCH] Update page/using-jquery-core/attributes.md --- page/using-jquery-core/attributes.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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.