On Aug 26, 11:48*am, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
Quote:
yawnmothwrote:
Quote:
[...]
If I comment out "document.getElemenById("demo").onmousedown =
mousedown;", it works. *Why would that make a difference?
>
Your forgot a "t".
Yup - thanks to both you and Stevo for pointing that out!
Quote:
The ID is unnecessary. *Probably someone has told you that before.
Someone has. Note that I didn't actually reference it with a
getElementById call. I just copy / pasted the HTML (I don't have the
DOCTYPE memorized, for instance) and I guess there was a redundancy I
was unaware of. Kinda like having any id that you don't use - they
could all be deleted if you noticed them.
Quote:
Quote:
<div style="background: black; width: 50px; height: 50px" id="demo">
>
You should also define the foreground color, and declare everything in the
CSS rule for the `#demo' selector.
I think for a real live production website that's definitely a good
idea. The main point of CSS is to separate content from aesthetics -
to make it so you don't have to edit the HTML to alter the layout.
For a quick little thing like this, though, I'm not sure why it'd
matter? If you had a style tag you could even split the CSS rules for
#demo up into multiple groups which would make it a bit more difficult
for someone to see what you're doing, even though it might be more
concise...
Quote:
Quote:
<script type="text/javascript">
document.body.onmouseup = mouseup;
document.getElemenById("demo").onmousedown = mousedown;
>
You should not be mixing proprietary and standards-compliant features (at
least not without feature test).
For that matter, it seems like feature tests are probably worth while
for even standards-compliant code? Just because someones browser
supports JavaScript1.3 doesn't mean someone can't come along with a
browser only supporting JavaScript1.2.
Quote:
Quote:
function mouseup() {
* alert("test");
}
>
Quote:
function mousedown() {}
>
Function expressions are widely supported nowadays, it does not appear
necessary to use function declarations here. *Especially not when you
use the W3C DOM which AFAIK was not implemented by user agents that only
supported JavaScript versions before 1.2.
I'll have to keep that in mind... thanks!