Opened 5 years ago

Closed 5 years ago

#31027 closed Cleanup/optimization (fixed)

Prefer DOM object properties over Element.getAttribute() and Element.setAttribute().

Reported by: Jon Dufresne Owned by: nobody
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Some JavaScript code uses Element.getAttribute() or Element.setAttribute() to access data that is available through a DOM object property. In general, the properties should be preferred as they are always normalized values and typed. The getAttribute()/setAttribute() are an abstraction over the serialized text representation.

Change History (3)

comment:2 by Mariusz Felisiak, 5 years ago

Summary: Prefer DOM object properties over Element.getAttribute() and Element.setAttribute()Prefer DOM object properties over Element.getAttribute() and Element.setAttribute().
Triage Stage: UnreviewedAccepted

I agree that we should prefer DOM properties but we need to be aware of differences and caveats (see comparison). For example href is quite tricky because as a DOM property it's always a full URL, even if the attribute contains a relative URL or just a # and of course on IE it doesn't work that way.

comment:3 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: newclosed

In cab36618:

Fixed #31027 -- Replaced .getAttribute()/.setAttribute() usage with DOM properties.

Note: See TracTickets for help on using tickets.
Back to Top