Solved

CDATA

Posted on 2012-03-10
5
405 Views
Last Modified: 2012-03-16
Can someone kindly explain what this code block is doing?  Inherited code and I am not familiar with CData.

  <script type='text/javascript'>
    //<![CDATA[
      !window.jQuery && document.write(unescape('%3Cscript src="../js/libs/jquery-1.7.1.min.js"%3E%3C/script%3E'));    // scripts concatenated and minified via ant build script
    //]]>
  </script>

Open in new window

0
Comment
Question by:kkbenj
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
StingRaY earned 250 total points
ID: 37704908
This script includes jQuery framework if it is not included.
CDATA block is a character data block, usually used in XHTML.
If you are writing a plain HTML, you can remove "//<![CDATA[" and "//]]>".
0
 
LVL 35

Assisted Solution

by:Robert Schutt
Robert Schutt earned 250 total points
ID: 37704910
The CDATA part is commented out but could be necessary to maintain valid xml/xsl at some other point.

The javascript code checks if jQuery is available and if not, insert the script tag to include it into the html.
0
 

Author Comment

by:kkbenj
ID: 37704916
Nothing in XHtml.  Thank you for the information.

One more related question: is that block of code even necessary since:
      <script src='../js/libs/jquery-1.7.1.min.js'></script>
is included in the header?
0
 
LVL 15

Expert Comment

by:StingRaY
ID: 37704917
No, it is not necessary anymore.
0
 

Author Closing Comment

by:kkbenj
ID: 37704920
Thank you both!
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question