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 -``` diff --git a/page/using-jquery-core/manipulating-elements.md b/page/using-jquery-core/manipulating-elements.md index d3fe9db1..fe70d2b1 100644 --- a/page/using-jquery-core/manipulating-elements.md +++ b/page/using-jquery-core/manipulating-elements.md @@ -132,23 +132,31 @@ 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()](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. ``` -// 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" }); ``` +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 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 ) {