From 88d1fc7b17739a5a0e642c3978dcdaadaed73569 Mon Sep 17 00:00:00 2001 From: Connor Cartwright Date: Wed, 4 May 2016 23:27:31 +0100 Subject: [PATCH 1/5] Spaced out the description and added in the getter/setter sentence from the attributes page --- page/using-jquery-core/manipulating-elements.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/page/using-jquery-core/manipulating-elements.md b/page/using-jquery-core/manipulating-elements.md index d3fe9db1..6099de18 100644 --- a/page/using-jquery-core/manipulating-elements.md +++ b/page/using-jquery-core/manipulating-elements.md @@ -132,7 +132,12 @@ myList.append( myItems.join( "" ) ); ## Manipulating Attributes -jQuery's attribute manipulation capabilities are extensive. Basic changes are simple, but the `.attr()` method also allows for more complex manipulations. It can either set an explicit value, or set a value using the return value of a function. When the function syntax is used, the function receives two arguments: the zero-based index of the element whose attribute is being changed, and the current value of the attribute being changed. +jQuery's attribute manipulation capabilities are extensive. +Basic changes are simple, but the `.attr()` method also allows for more complex manipulations. + +The `.attr()` method acts as both a getter and a setter. As a setter, `.attr()` can accept either a key and a value, or an object containing one or more key/value pairs. + +When the function syntax is used, the function receives two arguments: the zero-based index of the element whose attribute is being changed, and the current value of the attribute being changed. ``` // Manipulating a single attribute. From 3992b07edcd009101bc8dad4b3ee5ad51dc7863b Mon Sep 17 00:00:00 2001 From: Connor Cartwright Date: Wed, 4 May 2016 23:29:12 +0100 Subject: [PATCH 2/5] Changed terminology to set/setting, added example for getting a single attribute --- page/using-jquery-core/manipulating-elements.md | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/page/using-jquery-core/manipulating-elements.md b/page/using-jquery-core/manipulating-elements.md index 6099de18..347e3fe9 100644 --- a/page/using-jquery-core/manipulating-elements.md +++ b/page/using-jquery-core/manipulating-elements.md @@ -140,12 +140,17 @@ The `.attr()` method acts as both a getter and a setter. As a setter, `.attr()` When the function syntax is used, the function receives two arguments: the zero-based index of the element whose attribute is being changed, and the current value of the attribute being changed. ``` -// Manipulating a single attribute. +// Setting a single attribute. $( "#myDiv a:first" ).attr( "href", "newDestination.html" ); ``` ``` -// Manipulating multiple attributes. +// Getting a single attribute. +$( "a" ).attr( "href" ); // Returns the href for the first a element in the document +``` + +``` +// Setting multiple attributes. $( "#myDiv a:first" ).attr({ href: "newDestination.html", rel: "nofollow" @@ -153,7 +158,7 @@ $( "#myDiv a:first" ).attr({ ``` ``` -// Using a function to determine an attribute's new value. +// Using a function to set an attribute's new value. $( "#myDiv a:first" ).attr({ rel: "nofollow", href: function( idx, href ) { From 2693e10f9450ee67d79251df36b3b3717e1df2d5 Mon Sep 17 00:00:00 2001 From: Connor Cartwright Date: Wed, 4 May 2016 23:29:20 +0100 Subject: [PATCH 3/5] Removed attributes markdown file --- page/using-jquery-core/attributes.md | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 page/using-jquery-core/attributes.md diff --git a/page/using-jquery-core/attributes.md b/page/using-jquery-core/attributes.md deleted file mode 100644 index 0094e4ac..00000000 --- a/page/using-jquery-core/attributes.md +++ /dev/null @@ -1,27 +0,0 @@ - - -An element's attributes can contain useful information for your application, so it's important to be able to get and set them. - -## The `.attr()` method - -The `.attr()` method acts as both a getter and a setter. As a setter, `.attr()` can accept either a key and a value, or an object containing one or more key/value pairs. - -`.attr()` as a setter: - -``` -$( "a" ).attr( "href", "allMyHrefsAreTheSameNow.html" ); - -$( "a" ).attr({ - title: "all titles are the same too!", - href: "somethingNew.html" -}); -``` - -`.attr()` as a getter: - -``` -$( "a" ).attr( "href" ); // Returns the href for the first a element in the document -``` From d4c168aa190b06e75f115b8d201e17a18bf66318 Mon Sep 17 00:00:00 2001 From: Connor Cartwright Date: Wed, 4 May 2016 23:32:38 +0100 Subject: [PATCH 4/5] Moved the function syntax text down to sit next to the code example --- page/using-jquery-core/manipulating-elements.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/page/using-jquery-core/manipulating-elements.md b/page/using-jquery-core/manipulating-elements.md index 347e3fe9..4755ab4c 100644 --- a/page/using-jquery-core/manipulating-elements.md +++ b/page/using-jquery-core/manipulating-elements.md @@ -137,8 +137,6 @@ Basic changes are simple, but the `.attr()` method also allows for more complex The `.attr()` method acts as both a getter and a setter. As a setter, `.attr()` can accept either a key and a value, or an object containing one or more key/value pairs. -When the function syntax is used, the function receives two arguments: the zero-based index of the element whose attribute is being changed, and the current value of the attribute being changed. - ``` // Setting a single attribute. $( "#myDiv a:first" ).attr( "href", "newDestination.html" ); @@ -157,6 +155,8 @@ $( "#myDiv a:first" ).attr({ }); ``` +When the function syntax is used, the function receives two arguments: the zero-based index of the element whose attribute is being changed, and the current value of the attribute being changed: + ``` // Using a function to set an attribute's new value. $( "#myDiv a:first" ).attr({ From 12a85a808432003f236af73ef4cb7f0cf4d5cbbe Mon Sep 17 00:00:00 2001 From: Connor Cartwright Date: Thu, 5 May 2016 23:29:12 +0100 Subject: [PATCH 5/5] Added a link to the .attr API page and removed line spacing --- page/using-jquery-core/manipulating-elements.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/page/using-jquery-core/manipulating-elements.md b/page/using-jquery-core/manipulating-elements.md index 4755ab4c..fe70d2b1 100644 --- a/page/using-jquery-core/manipulating-elements.md +++ b/page/using-jquery-core/manipulating-elements.md @@ -132,9 +132,7 @@ myList.append( myItems.join( "" ) ); ## Manipulating Attributes -jQuery's attribute manipulation capabilities are extensive. -Basic changes are simple, but the `.attr()` method also allows for more complex manipulations. - +jQuery's attribute manipulation capabilities are extensive. Basic changes are simple, but the [.attr()](https://api.jquery.com/attr/) method also allows for more complex manipulations. The `.attr()` method acts as both a getter and a setter. As a setter, `.attr()` can accept either a key and a value, or an object containing one or more key/value pairs. ```