How to declare JavaScript and CSS XHTML-compatible?

Posted by joyce on Stack Overflow See other posts from Stack Overflow or by joyce
Published on 2010-05-21T17:01:26Z Indexed on 2010/05/21 17:20 UTC
Read the original article Hit count: 239

Filed under:
|
|

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";
...

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about css