When is a CDATA section necessary within a script tag?

A CDATA section is required if you need your document to parse as XML (e.g. when an XHTML page is interpreted as XML) and you want to be able to write literal i<10 and a && b instead of i&lt;10 and a &amp;&amp; b, as XHTML will parse the JavaScript code as parsed character data as opposed to character data by default. This … Read more

Defining a HTML template to append using JQuery

You could decide to make use of a templating engine in your project, such as: mustache underscore.js handlebars If you don’t want to include another library, John Resig offers a jQuery solution, similar to the one below. Browsers and screen readers ignore unrecognized script types: Using jQuery, adding rows based on the template would resemble:

momentJS date string add 5 days

UPDATED: January 19, 2016 As of moment 2.8.4 – use .add(5, ‘d’) (or .add(5, ‘days’)) instead of .add(‘d’, 5) Thanks @Bala for the information. UPDATED: March 21, 2014 This is what you’d have to do to get that format. Here’s an updated fiddle ORIGINAL: March 20, 2014 You’re not telling it how/what unit to add. Use –

Wait until flag=true

Because javascript in a browser is single threaded (except for webworkers which aren’t involved here) and one thread of javascript execution runs to completion before another can run, your statement: will simply run forever (or until the browser complains about a non-responsive javascript loop), the page will appear to be hung and no other javascript … Read more

How to initialize an array’s length in JavaScript?

Why do you want to initialize the length? Theoretically there is no need for this. It can even result in confusing behavior, because all tests that use the length to find out whether an array is empty or not will report that the array is not empty.Some tests show that setting the initial length of large arrays can be more efficient … Read more