SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Location
    Michigan
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    IE Mystery with className

    I have a Web page that runs properly with IE 9 with the following code:

    Code:
    // Check for IE
       if (isBrowserIE) tempArray[i].setAttribute("className", "red");
       else tempArray[i].setAttribute("class", "red");
    I have now created a new (separate) page that uses the SAME code--in fact, I did a copy and paste of the whole function containing this code segment 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. Thus using the same identical code, the older page worked (turned the text red) while the newer page did not.

    This would seem to be an impossible scenario. Any ideas?

    Incidently, the new page works on IE if I change "className" to "class". But if this is required to make the code work on the new page, then the older page that still has "className" should not work, but it does!

    Thanks so much.

    Ken

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by kenmorgan View Post
    Incidently, the new page works on IE if I change "className" to "class". But if this is required to make the code work on the new page, then the older page that still has "className" should not work, but it does!
    Why not just use object detection?

    Code javascript:
    if (tempArray[i].className) {
        tempArray[i].className = 'red';
    } else if (tempArray[i].class) {
        tempArray[i].class = 'red';
    }

    With which we can then extract out the class parts in to their own function:

    Code javascript:
    function setClass(el, className) {
        if (el.className) {
            el.className = className;
        } else if (el.class) {
            el.class = className;
        }
    }
     
    setClass(tempArray[i], 'red');
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What is the document mode (document.documentMode) for the new and old page? Document mode used by IE9 (and IE8) depends on X-UA-Compatible header and also on location of your pages. Intranet pages are by default running in different mode than Internet pages.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jan 2010
    Location
    Michigan
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, dherbolt. To answer your questions:

    (1) The doctype and <head> statements are identical:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
    
       <title>Interactive Bible quiz Daniel Hard</title>
       <meta name="author" content="Ken and Carol Morgan" />
       <meta name="classification" content="Bible Study" />
       <meta name="description" content="Daniel very difficult interactive Bible quiz" />
       <meta name="keywords" content="Nebuchadnezzar, Belshazzar, Hananiah, Azariah, Ashpenaz" />
       <meta name="robots" content="index, follow" />
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <meta http-equiv="Content-Language" content="en-us" />
       <link rel="stylesheet" type="text/css" href="BibleStyleRules.css" />
    Of course, the contents of the obvious meta statements differ--the new quiz is on Ezekiel. Nowhere do I have a line with X-UA or documentMode in either page. This is new to me. Some javascript is built into the two html pages, other sections brought in with src statements. The external js files are identical (used in many of our quizzes).

    (2) Both pages belong to the same Web site, are accessed via the same menu, and are being tested using the Internet and our server.

    Ken


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •