SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    stuck with IE...

    See this link:
    http://chowsreview.takeforce.net/rev/menu.php?vid=6
    In works perfect in Firefox, but when you open it in IE...

    The principle is based on changing CSS-class of the item group. I use Yahoo library for changing class and it works well everywhere. The thing I am stuck with is the following code:
    Code JavaScript:
    switch (sectionEl.className)
            {
                case "sectionExpanded":
                        oldClass = "sectionExpanded";
                        newClass = "sectionCollapsed";
                        break;
                case "sectionCollapsed":
                        oldClass = "sectionCollapsed";
                        newClass = "sectionExpanded";
                        break;
                case "subSectionExpanded":
                        oldClass = "subSectionExpanded";
                        newClass = "subSectionCollapsed";
                        break;
                case "subSectionCollapsed":
                        oldClass = "subSectionCollapsed";
                        newClass = "subSectionExpanded";
                        break;
            }
    What happens. Script is loaded, everything is OK. User clicks some control, it identifies which section we are working with (sectionEl element) Then depending on the currect class we detect, which class to set. This works well for the frst time. I click the group, it collapses or expands - ok. When I click it next time, className is OK (when I alert() it), but it doesn't fit any condition.

    Situation is stupid:
    Code JavaScript:
    alert(sectionEl.className)
    outputs (for instance):
    sectionExpanded
    but after this switch(), newClass is undefined

    But in FireFox it works well. What am I doing wrong?

    I even tried to change switch() to if():
    Code JavaScript:
    alert(sectionEl.className);
            alert(typeof sectionEl.className);
            oldClass = sectionEl.className;
            if (oldClass == "sectionExpanded")
            {
                newClass = "sectionCollapsed";
            }
            if (oldClass == "sectionCollapsed")
            {
                newClass = "sectionExpanded";
            }
            if (oldClass == "subSectionExpanded")
            {
                newClass = "subSectionCollapsed";
            }
            if (oldClass == "subSectionCollapsed")
            {
                newClass = "subSectionExpanded";
            }
            alert("old class: "+oldClass);
            alert("new class: "+newClass);
            YAHOO.util.Dom.replaceClass(sectionEl, oldClass, newClass);
            alert("result class: "+sectionEl.className);
    But it does the same. Works well for the first time. I checked type of the className - it's OK, it is string. It is compared to the string, but why comparison fails??? It fails in a strange way - first time it's OK, and next - fails.

    Any ideas?

    Thanks beforehand!

    PS. Is there any good debugger for IE like FireBug for FF?

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem seems to be that whitespace characters are being added around the class names since the class attribute takes a whitespace delimited list as its value. Since I assume you want to continue using YUI, the solution is to use another regular expression:
    Code:
    var matches = sectionEl.className.match(/(?:^|\s+)((?:subS|s)ection(?:Collapsed|Expanded))(?:\s+|$)/)
    if(matches.length) {
      switch(matches[1]){
        // cases go here
      }
    }
    Check these out:
    Internet Explorer Developer Toolbar
    Microsoft Script Debugger
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Addict KJedi's Avatar
    Join Date
    Sep 2005
    Location
    Ukraine, Nikolaev
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks!

    Thanks! Really, that was the problem

  4. #4
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have been trying to build a web site after reading Ian Lloyd's book Build Your Own Web Site. So, I am truly a novice. Towards the end of the book, Ian rightly suggests that one should test the look of the site through different browsers to be sure that it is accessible to all. I used IE 7 to build the site and then tried to check it using the latest version of Firefox. One problem that bothers me is that the font sizes change as one moves from one to the other. "Small" according to IE is indeed too small on Firefox. And x-small becomes unreadable in Firefox. What is the solution to this problem? Does Javescript have any role to play in this? I hope someone can help me out and I am aware that I know very little except the book I mentioned and a few internet sites.

  5. #5
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome, KJedi.

    d.dasgupta, next time, please start your own thread instead of asking a totally unrelated question in someone else's thread.

    Please post your code.(Put your code between [code][/code] tags.) And no, you shouldn't need JavaScript to make the font-size more consistent.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  6. #6
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry. I didn't mean to intrude, but I despite my membership status, I wasn't allowed to start a thread. But sorry again. I hope I can make use of your suggestion.

  7. #7
    SitePoint Member
    Join Date
    Oct 2006
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really don't want to post my code here since my problem is totally unrelated to the issues discussed here. Sorry again for the trouble.


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
  •