JavaScript And The rel Attribute

Browsers, JavaScript/Ajax Add comments

Working in JavaScript is one of my favorite things to do. I love how dynamic the language is and how powerful it can be. This programming dream is often turned into a nightmare by varying browser implementations, blatant disregard for accepted Web Standards (I’m looking at you IE), and a host of other odd things that can pop up.

The Problem

As is usually the case, Internet Explorer is very forgiving when it comes to the DOM and lots of times implements alternate methods of accessing certain functionality.

In my current project I am using the rel attribute to keep track of which row of data is being accessed. I know some of you may frown on this, however, it is an acceptable (to me) tactic as this is for a closed intranet where there is no concern for search engines. In Internet Explorer object.rel is an acceptable method for accessing the value of the rel attribute of a particular property.

Somehow I worked past this point without testing in Firefox so when an error kept occurring that was caused by Firefox not liking object.rel it took me a while to work back through the code to isolate this problem.

The Resolution

The problem has a really simple fix. In my case it was harder locating the problem then actually fixing it. To get around this problem you don’t need any object detection, you just need to use the standard method for accessing attributes, object.getAttribute(’rel’). Go figure.

The Moral Of This Story

The lesson that we should take away from this is to only use approved, standard methods of functionality. This too will lead you into problems due to inconsistent implementations but at least you are doing it the right way. You can then implement your own work-arounds or use a library like Dean Edwards’ IE7 script that will fill in all the holes in Internet Explorer to make it more standards compliant.

kick it on

Did You Enjoy This Post?

Be sure to grab my RSS feed so you don't miss out on more great articles.

This Post Was Brought To You By

Get FREE Magazines Forever! Looking for Computer, Business, Engineering, and Trade magazines and articles? We've got 'em. Get yours now!

How do I save time? I use FreshBooks for invoicing.

JavaScript And The rel Attribute

2 Responses to “JavaScript And The rel Attribute”

  1. cng Says:

    Sorry, but this article sounded like, “oh look everybody, I just discovered, that standards just matter, and ignoring them may bring problem!” while ignoring what are those browser wars (going on for a decade) all about.

  2. Rich Says:

    Sticking to standards worked for you in this case, but even sometimes the standard method of doing something isn’t the “cross browser compatible” solution. For example, getting or setting placement, scroll position, window dimensions, etc doesn’t work in any known standard way across all popular browsers. I use jQuery (though there are a lot of widely adopted frameworks like this to choose from) for even the most trivial JavaScript stuff, because whether the browsers all stick to the standard or if one or more even completely ignore the right way to do something, the library usually provides a much more browser agnostic experience.

    Over the years I’ve inherited a lot of code with “document.all” littered all over it and it drives me insane. I immediately convert everything to jQuery selectors before I do anything else.

Leave a Reply

WP Theme & Icons by N.Design Studio
Entries RSS Login