/    Sign up×
Community /Pin to ProfileBookmark

JavaScript & Transitional XHTML

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.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@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:&lt;script type="text/javascript"&gt;
[color=blue][b]//&lt;![CDATA[[/b][/color]
// ...
[color=blue][b]//]]&gt;[/b][/color]
&lt;/script&gt;
Though, you then have to ask yourself why you wouldn't just make an external JavaScript source file and then reference it &#8212; which, most of the time, is the better solution. Assuming [font=courier]foo.js[/font] contains all of your JavaScript&#58;&lt;script type="text/javascript" src="foo.js"&gt;&lt;/script&gt;[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).
  • [*]JavaScript is a case-sensitive language.
  • [/list]
    ×

    Success!

    Help @RandomUser spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.19,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...