Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question error with += in IE only?

    SOLUTION: I accidentally used <\ul> instead of </ul> ... IE actually threw a proper error, since \u escapes a unicode string (in hex)

    ---

    I have the following section of javascript:
    Code:
            jQuery.each($('.prodContent'), function(i, val) {
                if(!($(this).is(":has(ul.tabs)"))) {
                    jQuery.each($(this).children('.panes:has(.tabdiv)'), function(i, val) {
                        var theList = "<ul class='tabs'>\n";
                        jQuery.each($(this).children('.tabdiv'), function(i, val) {
                            var theName = $(this).children('.noshow:first').text();
                            theList += "    <li><a href='#'>"+theName+"</a></li>\n";
                        });
                        theList += "<\ul>\n";
                        $(this).before(theList);
                    });
                }
    In firefox and chrome, it takes a series of divs, containing headers, and adds a list of those headers before the series...

    so this:
    Code:
    <div>
    <h2>header1</h2>
    content
    </div>
    <div>
    <h2>header2</h2>
    content
    </div>
    becomes:
    Code:
    <ul>
    <li><a href="#">header1</a></li>
    <li><a href="#">header2</a></li>
    <div>
    <h2>header1</h2>
    content
    </div>
    <div>
    <h2>header2</h2>
    content
    </div>
    however, in IE, the error console claims an error on line 7, at the +=, saying that it expected a hexidecimal value... any ideas?

    p.s. you can see the issue live here http://bit.ly/oYrNAa (sorry bout the url shortener, but i don't want this topic to show up in a search for the site)
    Last edited by singedpiper; 09-27-2011 at 05:04 AM. Reason: show resolution

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    First question: What's the point of the arguments to that anonymous function:
    Code:
     function(i, val)
    ???
    The variables i and val aren't use in the body of the function, so why have them there? Granted, I can't see how it hurts, but...

    Anyway, did you try adding in some DEBUG code?

    Code:
            jQuery.each($('.prodContent'), function(i, val) {
                if(!($(this).is(":has(ul.tabs)"))) {
                    jQuery.each($(this).children('.panes:has(.tabdiv)'), function(i, val) {
                        var theList = "<ul class='tabs'>\n";
                        alert("initial value of theList:\n" + theList);
                        jQuery.each($(this).children('.tabdiv'), function(i, val) {
                            var theName = $(this).children('.noshow:first').text();
                            alert("value assigned to theName:\n" + theName;
                            theList += "    <li><a href='#'>"+theName+"</a></li>\n";
                            alert("after append, theList value is:\n" + theList);
                        });
                        alert("on exit from 'each', theList value is:\n" + theList);
                        theList += "<\ul>\n";
                        
                        $(this).before(theList);
                    });
                }
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    FWIW, when I hit that page with MSIE 7, I got the error on same line, but the error message was "Expected hexadecimal digit".

    Which is almost but not quite what you saw.

    My inclination would be to think that theName doesn't contain what you think it should.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    sorry, that is the message i got... I mistyped.

    the strangest thing is that it appears to be killing a lot of javascript on the page... alerts are not firing in IE, but in FF everything contains the data it should.

  • #5
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,885
    Thanks
    56
    Thanked 539 Times in 536 Posts
    I don't really understand alot of jQuery, but what I can see is that you are binding a click function to a div class button-cart but then the only thing I can find like that in your code is a class button-cart button

    dunno if that means anything...

  • #6
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    judging by the fact that I continue to get the error at position 39, even if i encrease the indent, it seems the actual line number might not be reporting accurately... it may be reporting the line number after all code is dynamically added by jquery.

  • #7
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,885
    Thanks
    56
    Thanked 539 Times in 536 Posts
    yeah, that's (one of) the problem with IE-only bugs - IE doesn't seem to be capable of telling you accurately which line is actually the problematic one...

  • #8
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    the bind is accurate, because the class, as recognized by jquery is both button-cart AND button... that's not it... by adding spaces strategically and testing where the error moved each time, i fond out that the error is with the line:

    Code:
                        theList += "<\ul>\n";
    which makes this a scope issue with the anonymous function... leaving the function must be deleting the var theList (i renamed it to theSetList on the live site)

    so, for do i rewrite that anonymous function as a for each?

  • #9
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    Could be (or could be not) the source of your errors. As a strict rule, in HTML and XHTML, the Doctype should be the very first declaration on the document. Anything written above (literal or as HTML/XHTML tag) will spoil things. After all, that is an XHTML document, not an XML document, thus the <?xml> declaration is useless.

    To set the character encoding you could use a meta tag in the HEAD section:
    Code:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #10
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    ugh... I'm dumb... the whole error was <\u> vs </u>

  • #11
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,028
    Thanks
    75
    Thanked 4,325 Times in 4,291 Posts
    LOL! Wonderful!

    You mean here:
    Code:
    theList += "<\ul>\n";
    So MSIE was actually *CORRECT*!!!

    \u is the start of a unicode escape sequence, and allows only hexadecimal characters to follow.

    WOW! You have to wonder how FF allowed that! It's actually a FF bug, not an MSIE bug.

    So now the score is FF 3918, MSIE 2.

    <grin/>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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