Solved

CDATA

Posted on 2012-03-10
5
401 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery scrollTop 2 40
What is assert.deepEqual? 4 39
window.setInterval not firing 7 29
Regular Expression 1-100 with two digits 15 21
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

943 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now