...

View Full Version : Resolved error with += in IE only?



singedpiper
09-26-2011, 04:46 AM
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:


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:


<div>
<h2>header1</h2>
content
</div>
<div>
<h2>header2</h2>
content
</div>

becomes:


<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)

Old Pedant
09-26-2011, 05:12 AM
First question: What's the point of the arguments to that anonymous function:


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?



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);
});
}

Old Pedant
09-26-2011, 05:23 AM
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.

singedpiper
09-26-2011, 02:49 PM
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.

xelawho
09-26-2011, 02:59 PM
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...

singedpiper
09-26-2011, 03:00 PM
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.

xelawho
09-26-2011, 03:03 PM
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... :mad:

singedpiper
09-26-2011, 03:18 PM
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:



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?

Kor
09-26-2011, 03:20 PM
<?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:


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

singedpiper
09-26-2011, 03:57 PM
ugh... I'm dumb... the whole error was <\u> vs </u>

Old Pedant
09-26-2011, 08:38 PM
LOL! Wonderful!

You mean here:


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/>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum