This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 27267 - Removal of DOMAttr.ownerElement breaks XPath functionality
Summary: Removal of DOMAttr.ownerElement breaks XPath functionality
Status: RESOLVED WORKSFORME
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: DOM (show other bugs)
Version: unspecified
Hardware: All All
: P2 critical
Target Milestone: ---
Assignee: Anne
QA Contact: public-webapps-bugzilla
URL: http://jsfiddle.net/psycketom/0cucudgk/
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-07 11:32 UTC by Toms
Modified: 2014-11-07 12:48 UTC (History)
2 users (show)

See Also:


Attachments

Description Toms 2014-11-07 11:32:08 UTC
Today I was greeted in my Chrome's console with this:

    'Attr.ownerElement' is deprecated and has been removed from DOM4 (http://w3.org/tr/dom).

Having quickly skimmed through the document, and finding out that "Attr" interface no more has the property, I did a quick Google search, which resulted in:

    http://stackoverflow.com/questions/24214188/attr-ownerelement-meaning

Specifically, this:

    "ownerElement" This property has been removed from Firefox 29. Since you can only get Attr objects from elements, you should already know the owner.

But this is wrong, really wrong. What about XPath, which allows us to query for nodes of specific type?

For instance, this query:

    descendant-or-self::*/attribute::*[starts-with(name(), "data-bind")]

Which does, something like "selects all attributes which names start with "data-bind" (data-bind, data-bind-something, data-bind-other) that are defined on either the context or any of the context node descendants". Emphasis on "selects all attributes" - this returns a result set of "Attr" nodes.

For instance, I have a JS model -> element binder library. I run the query, providing my element as the context and in return, I get all attributes that are responsible for binding.
By iterating over each of them and getting their type ("data-bind" as value binder and "data-bind-*" as attribute binder) and values, I can easily change "innerHTML/nodeValue" or "setAttribute" on the boundable element by utilising "Attr.ownerElement":

    if (attribute.name === 'data-bind')
    {
        attribute.ownerElement.innerHTML = providedModelData[attribute.value]; // Using the attributes' value as key here.
    }
    else
    {
        var targetAttributeName = attribute.name.replace('data-bind-', '');
        attribute.ownerElement.setAttribute(targetAttributeName, providedModelData[attribute.value]); // Again, using key and remainder of attributes value.
    }

XPath is the only option that allows us to query for attributes with wildcard names. And the combination of XPath, Attr and ownerElement is a magical one.

Clearly, the claim "Since you can only get Attr objects from elements, you should already know the owner." is wrong, at least in XPath context. Yes, with document.querySelector we will only get Element nodes, but hey - we got other querying possibilities!

Yes, I know that in my example, I can query for elements, that have the matching attributes, but then I have to loop through all of the attributes and filter them by names. Feels wrong, given that the current XPath/Attr/ownerElement combo can help us handling such case.

Maybe I have overlooked something and XPath will return a different Attr interface? Though, I highly doubt it.

To be honest, I'm really shocked.

I agree that separating Attr from Node is needed due to useless properties, but, please, oh please, leave the ownerElement intact.

P.S. A working example can be seen here: http://jsfiddle.net/psycketom/0cucudgk/
Comment 1 Anne 2014-11-07 11:50:35 UTC
https://dom.spec.whatwg.org/#dom-attr-ownerelement

I recommend filing a bug against Chrome for linking to out-of-date copies of standards.
Comment 2 Toms 2014-11-07 12:28:24 UTC
Oh my... Sorry for the false alert then.

But it appears that they're not only linking, but are going/were going towards implementing those.
Comment 3 Toms 2014-11-07 12:37:18 UTC
Hmm, but what about the information on MDN site? https://developer.mozilla.org/en-US/docs/Web/API/Attr

Still marked as: ownerElement [Deprecated since Gecko 7.0] [Obsolete since Gecko 29.0].
Comment 4 Anne 2014-11-07 12:39:53 UTC
We did recently change this. You might want to change the relevant content / file a bug on Firefox.

We thought it could be removed among with a lot of other things, but in the end we needed the association since we could not make values immutable.
Comment 5 Toms 2014-11-07 12:44:50 UTC
Is the idea of "ownerElement" removal still intact and may be removed in future?
Comment 6 Anne 2014-11-07 12:48:21 UTC
No, not really. See bug 25086.