Skip to content

Commit

Permalink
Clarify the return value of getAttribute (mdn#33363)
Browse files Browse the repository at this point in the history
* Clarify the return value of `getAttribute`

The returned value may not be a string. Absorb one subsection in "Description" to be more concisely explained under the "Return value" section.

* Remove a broken reference
  • Loading branch information
xuhdev authored May 2, 2024
1 parent f968988 commit 37aa127
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions files/en-us/web/api/element/getattribute/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ The **`getAttribute()`** method of the
{{domxref("Element")}} interface returns the value of a specified attribute on the
element.

If the given attribute does not exist, the value returned will
be `null`. See [Non-existing attributes](#non-existing_attributes) for details.
If the given attribute does not exist, the value returned will be `null`.

If you need to inspect the {{domxref("Attr")}} node's properties, you can use the {{domxref("Element.getAttributeNode()", "getAttributeNode()")}} method instead.

Expand All @@ -29,7 +28,7 @@ getAttribute(attributeName)

### Return value

A string containing the value of `attributeName`.
A string containing the value of `attributeName` if the attribute exists, otherwise `null`.

## Examples

Expand Down Expand Up @@ -57,10 +56,6 @@ const align = div1.getAttribute("align");
When called on an HTML element in a DOM flagged as an HTML document,
`getAttribute()` lower-cases its argument before proceeding.

### Non-existing attributes

All modern web browsers return `null` when the specified attribute does not exist on the specified element.

### Retrieving nonce values

For security reasons, [CSP](/en-US/docs/Web/HTTP/CSP) nonces from non-script
Expand Down

0 comments on commit 37aa127

Please sign in to comment.