Oliver Nassar

I can be reached at onassar@gmail.com.

For my open source work, check out github.com/onassar

grabbing an attribute in mootools: .[name] or .get or .retrieve or .getProperty?

View more posts

Something I ran into just now was returning an anchor's attribute consistently across browsers. So I have an anchor with an address like /users/delete/5/ which does what you'd think it does. But I ran into an inconsistent return response in (you guessed it) IE6. In all fairness, it might not be IE6s fault, but it speaks more to a problem with MooTools. While it is a nearly perfect library/framework, this does bug me.

MooTools has 3 native methods for accessing an attribute/property for a node (which in the DOM, often overlaps). .get('name'), .retrieve('name'), and .getProperty('name'). While they are all meant to do things a little differently (eg. set an attribute for a node, store a data object in an existing object (which could be a DOM node) or store a property in an object (which again, could be a DOM node), they seem to overlap a lot.

So I have this anchor, and when I tried accessing it (grabbing the href) using the accessors I have, here at the results for FF (mac) vs. IE6 (windows):


FF: full path including host
IE6: full path including host


FF: request path (excluding host)
IE6: full path including host


FF: null
IE6: null


FF: request path (excluding host)
IE6: full path including host

Now it's hard to say what is the correct expectation. I'm sure I could figure it out in the eyes of the W3C, but rather, here's what I've noticed. Both browsers take whatever path is specified and render it internally with the host. I understand this since it's what the browser would need to actually make a full request.

The 2nd and 4th accessors, though, are inconsistent and cause problems since their expected results different. IE6 includes the full path & host each time which is most likely an issue with how it accesses it. When the browser defines the href in memory it must overwrite the local pointer which then can't be accessed properly.

So what do I do about this? Nothing really. I have this documented now so that if there is a pre-dom-ready source that I need to inspect (for example, href values written but no rendered after the dom has been loaded), I should be using the .[name] accessor, and make adjustments accordingly based on what is being accessed (in this case the href which has the host prepended).

These differences really suck since they introduce inconsistencies in places where you wouldn't expect them and thus break applications/scripts (like what drove me to discover this). I would hope a framework/library would help mitigate this kind of thing, but alas, they can't do everything, and I'm just happy for what they do bring to the table.