AlloyUI - difference between node.attr("id") and node.getAttribute("id")

StackOverflow https://stackoverflow.com/questions/18325351

  •  25-06-2022
  •  | 
  •  

سؤال

In AUI, what is the difference between

node.attr("id")

and

node.getAttribute("id")

where node is an object of type Node.

The documentation on getAttribute says "Allows getting attributes on DOM nodes, normalizing in some cases." but I don't understand what normalizing means, and in what case it is applied.

Thanks, Alain

هل كانت مفيدة؟

المحلول

node.attr could be both getter and setter.

If you pass second argument to attr, it will be set as value of the attribute (the first argument).

node.getAttribute is only getter.

node.getAttribute normalizes the value for IE and especially for IE < 8. Without falling in many details, this means you may pass w3c standard attribute and it will work on all browsers.

Hope that helps!

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top