In DOM is it OK to use .notation for getting/setting attributes?
Posted
by Ziggy
on Stack Overflow
See other posts from Stack Overflow
or by Ziggy
Published on 2010-03-16T04:22:16Z
Indexed on
2010/03/16
13:26 UTC
Read the original article
Hit count: 254
Hi
In DOM, is it OK to refer to an element's attributes like this:
var universe = document.getElementById('universe');
universe.origin = 'big_bang';
universe.creator = null;
universe.style.deterministic = true;
? My deep respect for objects and their privacy, and my sense that things might go terribly wrong if I am not careful, makes me want to do everything more like this:
var universe = document.getElementById('universe');
if(universe.hasAttribute('origin')) then universe.origin = 'big_bang';
etc...
Is it really necessary to use those accessor methods? Of course it may be more or less necessary depending on how certain I am that the elements I am manipulating will have the attributes I expect them to, but in general do the DOM guys consider it OK to use .notation rather than getters and setters?
Thanks!
© Stack Overflow or respective owner