Skip to content

Update page/using-jquery-core/attributes.md #249

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions page/using-jquery-core/attributes.md
Original file line number Diff line number Diff line change
@@ -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.