Why? //<![CDATA[

Discussion in 'ASP .Net' started by shapper, Nov 26, 2007.

  1. shapper

    shapper Guest

    Hello,

    Why when I register some Javascript code to the page I get //<!
    [CDATA[ before it?

    <script type="text/javascript">
    //<![CDATA[
    $(document).ready(function(){
    This is the first script
    This is the second script
    });
    //]]>
    </script>

    If I write the script myself in the HTML code or using a literal do i
    need it?

    Thanks,
    Miguel
    shapper, Nov 26, 2007
    #1
    1. Advertising

  2. shapper

    bruce barker Guest

    to be xhtml compliant. in xhtml, special characters like "<" and ">"
    and more are not allowed unless contained in CDATA. so .net puts the
    script code in cdata tag. unfortunately, few browser support cdata tags
    in a script block, so the convention is to use javascript comments, to
    hide the cdata tags.

    -- bruce (sqlwork.com)


    shapper wrote:
    > Hello,
    >
    > Why when I register some Javascript code to the page I get //<!
    > [CDATA[ before it?
    >
    > <script type="text/javascript">
    > //<![CDATA[
    > $(document).ready(function(){
    > This is the first script
    > This is the second script
    > });
    > //]]>
    > </script>
    >
    > If I write the script myself in the HTML code or using a literal do i
    > need it?
    >
    > Thanks,
    > Miguel
    bruce barker, Nov 26, 2007
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Davison
    Replies:
    1
    Views:
    565
    Hal Rosser
    Jul 7, 2004
  2. Replies:
    3
    Views:
    728
    Joe Kesselman
    Mar 6, 2006
  3. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    839
    Mark Rae
    Dec 21, 2006
  4. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,681
    Smokey Grindel
    Dec 2, 2006
  5. Jake Barnes
    Replies:
    4
    Views:
    106
    Thomas 'PointedEars' Lahn
    Jan 8, 2006
Loading...

Share This Page