[Javascript] removeAttribute issue IE7

Rees, Mark Mark.Rees at astrazeneca.com
Tue May 4 03:47:01 CDT 2010


IE 6 and 7 at least use 'className' instead of 'class' to refer to the class attribute, as you have discovered. Another difference you will come across at some point is the for attribute, as used on the label element for example. That is called htmlFor in IE6 (and maybe 7). 

There are a couple of ways around this. If you are using a JavaScript library such as jQuery or Prototype, the get/setAttribute function in that library will certainly solve this problem for you. However if you are writing your own function, it needs to do something along these lines:

if(div.getAttribute('class')){
	div.removeAttribute('class');
}else{
	div.removeAttribute('className');
}
	


--------------------------------------------------------------------------
AstraZeneca UK Limited is a company incorporated in England and Wales with registered number: 03674842 and a registered office at 15 Stanhope Gate, London W1K 1LN.
Confidentiality Notice: This message is private and may contain confidential, proprietary and legally privileged information. If you have received this message in error, please notify us and remove it from your system and note that you must not copy, distribute or take any action in reliance on it. Any unauthorised use or disclosure of the contents of this message is not permitted and may be unlawful.
Disclaimer: Email messages may be subject to delays, interception, non-delivery and unauthorised alterations. Therefore, information expressed in this message is not given or endorsed by AstraZeneca UK Limited unless otherwise notified by an authorised representative independent of this message. No contractual relationship is created by this message by any person unless specifically indicated by agreement in writing other than email.
Monitoring: AstraZeneca UK Limited may monitor email traffic data and content for the purposes of the prevention and detection of crime, ensuring the security of our computer systems and checking Compliance with our Code of Conduct and Policies.
-----Original Message-----
From: javascript-bounces at lists.evolt.org
[mailto:javascript-bounces at lists.evolt.org]On Behalf Of jeffrey morin
Sent: 19 April 2010 18:12
To: javascript at lists.evolt.org
Subject: [Javascript] removeAttribute issue IE7


Hey everyone,

I am editing a script that is having issues in IE7 and can't figure this
out. A radio button has an onclick event handler and when it is fired it
calls a script that removes a class name from a div element. For whatever
reason it doesn't work for IE7 though.

It is very straight forward and says just this.

var div = document.getElementById('div')
div.removeAttribute('class')

I threw an alert in there to give the class name and Ie returns it as null.
The weird thing is that when I just use div.className = ' ' it works just
fine. Does anyone know what is going on here? I am stumped.

Thanks,
- J
_______________________________________________
Javascript mailing list
Javascript at lists.evolt.org
http://lists.evolt.org/mailman/listinfo/javascript


More information about the Javascript mailing list