Is it considered good practice to use DOM Element’s getAttribute/setAttribute calls to associate additional information about contents of the element ?
For example I want to call setAttribute("MY_ATTRIBUTE_VALUE", "..."), where MY_ATTRIBUTE_VALUE isn’t anything applicable to <div>.
Thanks !
It is very good practise as long as you’re setting custom data attributes, whose purpose is holding meta data about those elements. Data attributes take the form
data-namewherenamecan be any valid descriptor.Traditionally people would add classes, and in some cases this is still appropriate (e.g. when a class describes the state of an attribute and also denotes a style class, for which class is primarily used).