Is it safe to use JavaScript whilst also having your code categorised under the XHTML 1.0 Transitional DTD? One more thing, hehe, would JavaScript coding in small caps be safe to use or will this affect the result of your JavaScript coding? Thank you for reading.
@fredmvApr 07.2004 — #[i]Originally posted by RandomUser [/i]
[B]Is it safe to use JavaScript whilst also having your code categorised under the XHTML 1.0 Transitional DTD?[/B][/QUOTE]Absolutely. Though, a quite notable thing that you should be aware of is that some scripts might reqire a bit of tweaking if you've been using them under quirks mode previously. A prime example of this is when you do something like this (assuming [font=courier]foo[/font] hold a reference to an [font=courier]HTMLElement[/font] object):foo.style.top = 5;When in reality (i.e., under standards-compliance mode), you [b]must[/b] specify the unit in question to get things working properly:foo.style.top = '5px';There could be some other possibly weird quirks as well, but this has to be the most common one I've come across. Generally, if your JavaScript is written correctly it shouldn't be a problem. Moreover, remember that XHTML [b]is[/b] XML thus when having embedded JavaScript (i.e., via the [font=courier]<script>[/font] element) it is generally a good practice to encase it in a XML CDATA block:<script type="text/javascript"> [color=blue][b]//<![CDATA[[/b][/color] // ... [color=blue][b]//]]>[/b][/color] </script>Though, you then have to ask yourself why you wouldn't just make an external JavaScript source file and then reference it — which, most of the time, is the better solution. Assuming [font=courier]foo.js[/font] contains all of your JavaScript:<script type="text/javascript" src="foo.js"></script>[i]Originally posted by RandomUser [/i]
[B]One more thing, hehe, would JavaScript coding in small caps be safe to use or will this affect the result of your JavaScript coding?[/B][/QUOTE]I'll explain. JavaScript is a case-sensitive language. This means that [font=courier]foo[/font] is different from [font=courier]Foo[/font] which is different from [font=courier]FOO[/font] and so on. Thus, you must be careful when defining variables and even more importantly, using them later on! This rule also heavily applies when using predefined objects and methods provided by JavaScript. A prime example of this would be trying to access the user's browser version. The correct notation would be something like:var ver = navigator.appVersion;However, if you didn't case everything properly, and did something like this (carefully note the lowercase "V" in [font=courier]appVersion[/font]):var ver = navigator.appversion;It would simply not work correctly due to JavaScript being case-sensitive. Keep this in mind and you should have a lot less bugs to deal with.
So, to re-iterate:[list=a]
[*]It is safe to use JavaScript under an XHTML DOCTYPE (with some circumstances).