Custom JavaScript attributes work differently in IE compared to Firefox
Adding custom attributes to HTML tags is a really valuable programming method. It's something I do quite often.
Consider the following code:
<script>
function DoSomething(el){
alert(el.contentId);
}
</script>
<div contentId="123" editable="true" onclick="DoSomething(this)">Some Text</div>
The above code would work in IE6+ but would fail in Firefox.
The solution
In Firefox you need to use one of the following alternatives to read the attribute value back (these also work in IE)
el.attributes["contentId"];
el.getAttribute("contentId");
I guess we should all be using these rather than the helpful IE code... old habits die hard though.
| Author |
: Paul Hayman |
| Published |
: Wednesday, 01 August, 2007 |
Paul is the COO of kwiboo ltd consultant and has more than a decade of IT consultancy experience. He has consulted for a number of blue chip companies and has been exposed to the folowing sectors: Utilities, Telecommunications, Insurance, Media, Investment Banking, Leisure, Legal, CRM, Pharmaceuticals, Interactive Gaming, Mobile Communications, Online Services.
Paul is the COO and co-founder of kwiboo (http://www.kwiboo.com/) and is also the creator of GeekZilla.