-
Notifications
You must be signed in to change notification settings - Fork 480
Merging attributes page into Manipulating Elements #713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
88d1fc7
3992b07
2693e10
d4c168a
12a85a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,23 +132,33 @@ 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can link back to the relevant page of the API? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @AurelioDeRosa good point! I agree that would be useful |
||
|
||
``` | ||
// 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 ) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably this line and the next can be combined with the previous one. I'm not sure we need break lines in between.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @AurelioDeRosa on this one