How to declare JavaScript and CSS XHTML-compatible?
- by joyce
Hi! I'm wondering how to declare JavaScript code within a CDATA section so that it is compatible with XHTML. Which method is correct/recommended?
Method 1:
<script type="text/javascript">
// <![CDATA[
CODE
// ]]>
</script>
Method 2:
<script type="text/javascript">
/* <![CDATA[ */
CODE
/* ]]> */
</script>
Is the second one also suitable for inline CSS?
And, is it possible/does it make sense to add some encoding declaration here like
<script type="text/javascript" charset="utf-8">
...
<style type="text/css" media="screen" charset="utf-8">
...
or
<script type="text/javascript">
@charset "utf-8";
...
<style type="text/css" media="screen">
@charset "utf-8";
...