On Jan 20, 12:10 am, Diego Perini <diego.per...@gmail.com> wrote: > On Jan 19, 8:29 am, RobG <rg...@iinet.net.au> wrote: > > On Jan 19, 1:49 pm, Diego Perini <diego.per...@gmail.com> wrote: [...] > > > I don't know if there are known problems using these "defaultXXXXXX" > > > DOM properties. Anybody have reasons against their usage ? > > > Not in regard to their use, but the reason for using them should not > > be to (attempt to) modify the related HTML attribute. > > When writing to the "default*" property values, whatever the reason > and the objective is, there is no way that I known to avoid also > modifying HTML attribute and related DOM properties.
My views on the use of attributes are based on the principle that HTML (and XML and JSON) are just a data delivery mechanisms, the DOM and the data structure of the application should be the primary focus of scripting. Using attributes only for initial state and thereafter using object properties frees you from having to worry about the foibles of attributes. Attributes cause issues not only because the relationship between DOM properties and HTML attributes aren't tightly specified, but also because browsers treat non-standard attributes differently. If you adopt the principle above, life is much easier. Where there is a need to associate data with a DOM object, data structures should be created that link to the associated DOM object. Non-standard properties should not be added to DOM objects. The introduction of HTML data- attributes muddies the water somewhat (quite apart from indicating that the use of XHTML to provide for custom data attributes within markup was not sufficient motivation for it to replace HTML 4) because in some browsers these non-standard attributes can only be accessed using getAttribute. This tends to suggest that the associated data should be maintained within the attribute, but I would not to that. Other schemes can provide the same functionality without the need to add data to the markup. From an implementation perspective, accessing a DOM element attribute is not much different to accessing an object property, the difference is that attributes have many foibles, object properties have very few. I don't see data- attributes as anything earth shattering, they don't change my general view regarding attributes. As an aside, the use of data- attributes has promoted the use of Model View ViewModel (MVVM[1]) as an alternative to MVC for web applications. Anyhow, just thought I'd provide some background to my views. 1. http://en.wikipedia.org/wiki/Model_View_ViewModel -- Rob -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com