skaterdav85 Posted March 9, 2011 Share Posted March 9, 2011 I never really understood the difference between using elem.getAttribute() or accessing an attribute using the dot property approach like elem.id. Anyone know the difference? Link to comment Share on other sites More sharing options...
Ingolme Posted March 9, 2011 Share Posted March 9, 2011 The difference is that getAttribute can access any attribute with any name, while using "." can only access the "attributes" that were set as object properties in the HTML DOM specification.In XML, for example, you won't be allowed to access attributes with "." because there are no properties assigned to them.A good example of the difference between an attribute and a property can be seen in the Anchor object: http://w3schools.com/jsref/dom_obj_anchor.aspIf you use anchor.getAttribute("href") it may return something like "page.html" while if you use anchor.href it will return "http://mysite.com/page.html" Link to comment Share on other sites More sharing options...
skaterdav85 Posted March 9, 2011 Author Share Posted March 9, 2011 oh ok that clears it up. thanks! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.