Are single/double quotes allowed inside HTML attribute values?

Yes, both quotes are allowed in attribute values, but you must HTML-escape the quote you’re using as an attribute value delimiter, as well as other HTML-special characters like < and &: function encodeHTML(s) { return s.split(‘&’).join(‘&amp;’).split(‘<‘).join(‘&lt;’).split(‘”‘).join(‘&quot;’).split(“‘”).join(‘&#39;’); } var html=”<label my_attr=””+encodeHTML(attr_value)+'”>Text</label>’; However, you are usually much better off not trying to hack a document together from … Read more

How to detect supported video formats for the HTML5 video tag?

You can check codecs for different video types with HTMLVideoElement.prototype.canPlayType. There is also a great HTML5 feature detection library, Modernizr. var testEl = document.createElement( “video” ), mpeg4, h264, ogg, webm; if ( testEl.canPlayType ) { // Check for MPEG-4 support mpeg4 = “” !== testEl.canPlayType( ‘video/mp4; codecs=”mp4v.20.8″‘ ); // Check for h264 support h264 = … Read more

Directly reference HTML elements [duplicate]

Being able to select elements on the page based on their [id] is a “feature” from early JavaScript (DOM lvl 0 or 1 methinks, can’t seem to find the source). Unfortunately it’s a temperamental feature. What would happen if you had: <div id=”window”></div> or <div id=”document”></div> Better yet, what happens here? <div id=”foo”></div> <div id=”bar”></div> … Read more

multiple selections with datalist

Multiple currently working only with input type=”email” and only in Chrome and Opera Look at this minimalist example: input{width:500px} <input type=”email” list=”emails” multiple> <datalist id=”emails”> <option value=””> <option value=””> <option value=””> <option value=””> </datalist> <br><br><br> <input type=”text” list=”texts” multiple> <datalist id=”texts”> <option value=”black”> <option value=”gold”> <option value=”grey”> <option value=”pink”> <option value=”turquoise”> <option value=”red”> <option value=”white”> … Read more