whatwg / dom

DOM Standard
https://dom.spec.whatwg.org/
Other
1.57k stars 290 forks source link

"Attr? setAttributeNode(Attr attr);" #205

Open senolv opened 8 years ago

senolv commented 8 years ago

https://dom.spec.whatwg.org/#dom-element-getattributenodens-namespace-localname-localname

Attr? setAttributeNode(Attr attr); and all the other methods like ...AttributeNode() are we now encouraged to use again? or should we prefer attributes.setNamedItem or Element.setAttribue?

ArkadiuszMichalski commented 8 years ago

They have been restored in one package because usage some of them was hight (https://www.w3.org/Bugs/Public/show_bug.cgi?id=27344 https://www.w3.org/Bugs/Public/show_bug.cgi?id=25016). In some case they are redefined and now works identically (https://github.com/whatwg/dom/issues/117). The best would be no longer use them but it's depends how you works around attrs. Using reflect, Element.setAttribute()/getAttribute()/hasAttribute()/removeAttribute() in most case are sufficient. And some other thoughts about this mess: https://annevankesteren.nl/2014/08/attributes

senolv commented 8 years ago

This is a really sufficient pro answer, thanks a lot.

annevk commented 8 years ago

Yeah, I guess I should add a note that .attributes is largely there for historical reasons, as we do with some other features.

senolv commented 8 years ago

May be this question could help you too.

Ok let us concentrate on using:

Element.setAttribute()/getAttribute()/hasAttribute()/removeAttribute()

But how can we determine what nodeType we have -if we need this- without using:

attributes or getAttributeNode(), since getAttribute() returns a String where .nodeType will end up with undefined?

ArkadiuszMichalski commented 8 years ago

As I wrote earlier it depends on how you work with attributes. But in practice attrs not participates in tree so you don't get mixed other nodes with attrs, you don't have to verify attrs. And there are plans to stop inherits Attr from Node (still discussion https://github.com/whatwg/dom/issues/102). Start thinking about the attributes not as the nodes because it was a mistake which is hard to correct now.