Solved

CDATA

Posted on 2012-03-10
5
400 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
No, it is not necessary anymore.
0
 

Author Closing Comment

by:kkbenj
Comment Utility
Thank you both!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

772 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

13 Experts available now in Live!

Get 1:1 Help Now