IE Mystery with className
I have a Web page that runs properly with IE 9 with the following code:
I have now created a new (separate) page that uses the SAME code--I did a copy and paste of the whole function containing this code from the page that works into the new page. However, the function (this if-statement in particular) does not work in the new page--the new page does NOT make the array item red, BUT it does make it red if I change "className" to "class"--just as if IE now uses "class" like everyone else. But then the older page that still has "className" should not work, but it does!
// Check for IE
if (isBrowserIE) tempArray[i].setAttribute("className", "red");
else tempArray[i].setAttribute("class", "red");
This would seem to be an impossible scenario. Any ideas?
Thanks so much.
Never use class as its likely to be a reserved word, and never use setAttribute unless direct assignment fails.
This should always work:
tempArray[i].className = 'red';
Where used, return should be executed unconditionally and always as the last statement in the function.
That's my signature, it's not part of the damn post!
Thanks, Logic Ali.
(1) Your more concise code did work, and since it is more concise and direct, I'll probably switch to it. However, my code also worked in IE 9 by simply using "class" rather than "className" in the code segment posted.
(2) My real question was why my original code worked in IE 9 on one page but did not work on another page on which the whole function containing that code was copy and pasted. The code I posted was identical on the two pages. One page worked (turned the text red) and the other page did not. I was hoping to find an explanation for THAT! As I said in my original post, that would seem to be impossible.
Last edited by kenmorgan; 10-22-2012 at 11:46 AM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)