Jump to content

createElement attributing


absorr

Recommended Posts

Usually, you just do:

element.attributeName = ...;

where attributeName is the name of the attribute you're trying to set. However, some are a little different. For example, to set the class attribute you'd do:

element.className

instead of just

element.class

Link to comment
Share on other sites

Usually, you just do:
element.attributeName = ...;

where attributeName is the name of the attribute you're trying to set. However, some are a little different. For example, to set the class attribute you'd do:

element.className

instead of just

element.class

Technically, those aren't attributes. They're properties belonging to the DOM element. For most attributes defined by the W3C browsers create a property. If you want to access a non-standard attribute you will need to use the .getAttribute() method.
Link to comment
Share on other sites

Technically, those aren't attributes. They're properties belonging to the DOM element...
Thats currect bro, but since those properties represent HTML element's attributes, i think it can also be called attributes (Just my own opinion).
Link to comment
Share on other sites

Technically, those aren't attributes. They're properties belonging to the DOM element. For most attributes defined by the W3C browsers create a property. If you want to access a non-standard attribute you will need to use the .getAttribute() method.
True, but that is, AFAIK, the most reliable way to set attributes on an element created using document.createElement(). I thought there were some cross browser issues with setAttribute.
Link to comment
Share on other sites

True, but that is, AFAIK, the most reliable way to set attributes on an element created using document.createElement(). I thought there were some cross browser issues with setAttribute.
The difference appears when attempting to use custom properties and attributes.If you set the property "custom" rather than setting attribute "custom" then, theoretically, it won't show up when printing out the innerHTML of the parent.If you hardcoded an attribute "custom" onto any particular element then, theoretically, you can only access its value using getAttribute(). The idea, anyways, is to know when to manipulate properties and when to manipulate attributes.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...