14 ms·
That's all true, but is there anything practical you can do with an attribute node, and el.attributes, that you can't do with setAttribute/getAttribute/getAttri
by jaffathecake 2y ago
That's all true, but is there anything practical you can do with an attribute node, and el.attributes, that you can't do with setAttribute/getAttribute/getAttributeNames/hasAttribute?
You can't even move attribute nodes between elements. You can't event reorder attribute nodes within an element.
- aragonite 2y agoNot that I know of! It's just a way to help myself keep the distinction straight mentally. If at the back of my head I always think of attributes as DOM nodes in their own right, I'm much less tempted to infer from a DOM element having a particular attribute to it possessing a particular property, and vice versa.
- dylan604 2y agowhy do you care what order the attributes are in that you feel not being able to reorder them is a negative?
- deleted 2y ago[deleted]
- jaffathecake 2y agoI don't. I was just trying to think of anything an iterable might offer over the other methods.
- jgraham 2y agoWork with attributes whose name doesn't match the XML Name production. That can be a real concern in some cases (it came up recently in the context of "how do I move all the attributes on node A to node B, given that node A's attributes can be anything that can be created by the HTML parser?" c.f. https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=12541 https://software.hixie.ch/utilities/js/live-dom-viewer/?save... )
- jaffathecake 2y agoHah, good insight! I didn't realise you could move attributes either. I tried, but seems (unlike nodes) you need to remove them before adding them.
- paulddraper 2y agoLook at the DOM Attr interface [1]. You can list attributes, get their name, namespace, value. [1] https://developer.mozilla.org/en-US/docs/Web/API/Attr https://developer.mozilla.org/en-US/docs/Web/API/Attr
- jaffathecake 2y agoAll of which you can do with the other methods.
- paulddraper 2y agoSure