By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,659 Members | 1,945 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,659 IT Pros & Developers. It's quick & easy.

weird IE bug

P: n/a
I found what looks like a definite bug in IE. If you load the page
below in Firefox, the alert comes up as you would expect. If you run it
in IE6 (with sp2), the alert doesn't come up. commenting out the line
that starts 'div.class' makes it work. This is very weird, as far as I
can see - the code is not run, and it's not generating a syntax error,
but it's still preventing the rest of the program from running. All I
can guess is that the javascript parser has crashed on that line for
some reason without returning an error. It is possible to work round
this using setAttribute, but it's annoying nonetheless.

<html>
<head><title>bug test</title>
<script type="text/javascript">
function notCalled() {
var div=document.createElement("div");
div.class="tabContentPaneDiv";
}

alert("here");
</script>
</head>
<body>
<h1>IE Bug Test</h1>
</body>
</html>

Jun 12 '06 #1
Share this Question
Share on Google+
11 Replies


P: n/a

lo*****@fastmail.fm wrote:
div.class="tabContentPaneDiv";


There is no bug. To alter a class for an element, the correct syntax
is:

element.className = "classname";

Changing it to the above will cause your alert to show up.

Jun 12 '06 #2

P: n/a

web.dev wrote:
lo*****@fastmail.fm wrote:
div.class="tabContentPaneDiv";


There is no bug. To alter a class for an element, the correct syntax
is:

element.className = "classname";

Changing it to the above will cause your alert to show up.


OK - I had the wrong attribute name for what I was originally trying to
do, but there is still a bug as far as I can see. If you change the
line above it so the function reads:

function notCalled() {
var div={class:0};
div.class="tabContentPaneDiv";
}

The alert doesn't show up. It does in Firefox. This shouldn't happen I
think.

The point is the function is never called, so the only time the
javascript interpreter should look at it is when checking for syntax.
At this point, the interpreter shouldn't be bothered whether the div
variable is a dom node or some other kind of object. But even though
it's not called, assigning to the property name 'class' causes the
program never to be run.

Jun 12 '06 #3

P: n/a

loft...@fastmail.fm wrote:
web.dev wrote:
lo*****@fastmail.fm wrote:
div.class="tabContentPaneDiv";


There is no bug. To alter a class for an element, the correct syntax
is:

element.className = "classname";

Changing it to the above will cause your alert to show up.


OK - I had the wrong attribute name for what I was originally trying to
do, but there is still a bug as far as I can see. If you change the
line above it so the function reads:

function notCalled() {
var div={class:0};
div.class="tabContentPaneDiv";
}

The alert doesn't show up. It does in Firefox. This shouldn't happen I
think.

The point is the function is never called, so the only time the
javascript interpreter should look at it is when checking for syntax.
At this point, the interpreter shouldn't be bothered whether the div
variable is a dom node or some other kind of object. But even though
it's not called, assigning to the property name 'class' causes the
program never to be run.


I just found out that 'class' is a reserved word in javascript, which
may explain this, though if it is, the interpreter should give a syntax
error, not just stop. This also doesn't explain why it runs OK in
firefox.

Jun 12 '06 #4

P: n/a
lo*****@fastmail.fm wrote:
function notCalled() {
var div={class:0};
div.class="tabContentPaneDiv";
}
The alert doesn't show up. It does in Firefox. This shouldn't happen I
think.


I think IE behaves more appropriately.
'class' is a reserved word and can't be used in the manner you are using it.
A decent JS editor will highlight the word and you would know something is
wrong. Further, I *do* get an error in IE. Perhaps your errors are set to
not pop up.

Try this code:

function notCalled() {
var div={'class':0};
div['class']="tabContentPaneDiv";
}
alert ('x');

Works just fine.

--
Matt Kruse
http://www.JavascriptToolbox.com
http://www.AjaxToolbox.com
Jun 12 '06 #5

P: n/a
lo*****@fastmail.fm wrote:
loft...@fastmail.fm wrote:

I just found out that 'class' is a reserved word in javascript, which
may explain this, though if it is, the interpreter should give a syntax
error, not just stop.
"It would be nice if IE did..."

but it doesn't, so you deal with it. IE pretty much doesn't give errors.

This also doesn't explain why it runs OK in
firefox.


Firefox ignores it as a keyword (at least in that context) and keeps on
going.
--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"
Jun 13 '06 #6

P: n/a
Tony said the following on 6/12/2006 8:58 PM:
lo*****@fastmail.fm wrote:
loft...@fastmail.fm wrote:

I just found out that 'class' is a reserved word in javascript, which
may explain this, though if it is, the interpreter should give a syntax
error, not just stop.
"It would be nice if IE did..."

but it doesn't, so you deal with it. IE pretty much doesn't give errors.


Yes it does, you just have to learn how to understand them. And
sometimes, IE gives better (more useful) error messages than FF does.
This also doesn't explain why it runs OK in
firefox.


Firefox ignores it as a keyword (at least in that context) and keeps on
going.


Then FF is wrong in that instance. 'class' is a reserved word and FF
should throw an error when it encounters it.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 13 '06 #7

P: n/a
Randy Webb <Hi************@aol.com> writes:
Then FF is wrong in that instance. 'class' is a reserved word and FF
should throw an error when it encounters it.


Javascript is allowed to delay failing until the erroneous code is
executed.
I would prefer Firefox to err early (a good principle), but it is allowed
to do as it does (ECMAS262 3rd ed, section 16).
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 13 '06 #8

P: n/a
Randy Webb wrote:
Tony said the following on 6/12/2006 8:58 PM:

"It would be nice if IE did..."

but it doesn't, so you deal with it. IE pretty much doesn't give errors.

Yes it does, you just have to learn how to understand them. And
sometimes, IE gives better (more useful) error messages than FF does.


I haven't found that to be the case - perhaps I just haven't encountered
such a situation.
This also doesn't explain why it runs OK in
firefox.


Firefox ignores it as a keyword (at least in that context) and keeps
on going.


Then FF is wrong in that instance. 'class' is a reserved word and FF
should throw an error when it encounters it.


Probably - especially as FF claims to support "JavaScript 2.0".
--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"
Jun 14 '06 #9

P: n/a
Tony said the following on 6/14/2006 2:09 PM:
Randy Webb wrote:
Tony said the following on 6/12/2006 8:58 PM:

"It would be nice if IE did..."

but it doesn't, so you deal with it. IE pretty much doesn't give errors.

Yes it does, you just have to learn how to understand them. And
sometimes, IE gives better (more useful) error messages than FF does.


I haven't found that to be the case - perhaps I just haven't encountered
such a situation.


A lot of that depends on what you get used to. The first that comes to
mind is something like this:

<script type="text/javascript" src="ExternalJsFile.js"></script>
<script type="text/javascript">
someFunctionInExternalJsFile()
</script>

Now, assume you have the path wrong to the ExternalJsFile.js, or, you
have a typo in the name of the file.

IE error message:

Line: 2
Character: 1
Error: Invalid Character

FF error message:

Error: someFunctionIn is not defined

Neither exactly tells you what the problem is - that the external file
didn't get loaded. But IE never makes it to the function call. So which
is a better error message?

That is the first that comes to mind because I have seen it so many
times that when I see it I already know what is wrong without looking.

That doesn't mean I think IE always gives better error messages because
it doesn't. But FF doesn't always either. A better error message for the
above problem would be something like "File failed to load" or "File not
found". But both IE and FF's error message was useless.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 16 '06 #10

P: n/a
Randy Webb wrote:
Tony said the following on 6/14/2006 2:09 PM:
Randy Webb wrote:
Yes it does, you just have to learn how to understand them. And
sometimes, IE gives better (more useful) error messages than FF does.
I haven't found that to be the case - perhaps I just haven't
encountered such a situation.


A lot of that depends on what you get used to. The first that comes to
mind is something like this:

<script type="text/javascript" src="ExternalJsFile.js"></script>
<script type="text/javascript">
someFunctionInExternalJsFile()
</script>

Now, assume you have the path wrong to the ExternalJsFile.js, or, you
have a typo in the name of the file.

IE error message:

Line: 2
Character: 1
Error: Invalid Character

FF error message:

Error: someFunctionIn is not defined

Neither exactly tells you what the problem is - that the external file
didn't get loaded. But IE never makes it to the function call. So which
is a better error message?

That is the first that comes to mind because I have seen it so many
times that when I see it I already know what is wrong without looking.


Hm - I suppose I can see that. To me, the Firefox error is better. But
if the IE one works better for you, I certainly won't argue.
That doesn't mean I think IE always gives better error messages because
it doesn't. But FF doesn't always either. A better error message for the
above problem would be something like "File failed to load" or "File not
found". But both IE and FF's error message was useless.


I'd say I agree on that point.

--
"The most convoluted explanation that fits all the available and made-up
facts is the most likely to be believed by conspiracy theorists"
Jun 16 '06 #11

P: n/a
Tony said the following on 6/16/2006 1:40 PM:
Randy Webb wrote:


<snip>
That doesn't mean I think IE always gives better error messages
because it doesn't. But FF doesn't always either. A better error
message for the above problem would be something like "File failed to
load" or "File not found". But both IE and FF's error message was
useless.


I'd say I agree on that point.


The error message for that code when run in Opera9 is:

Event thread: BeforeExternalScript
Linked script not loaded

Now *that* is a useful error message :)

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jun 16 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.