Watching for DOM changes, the elegant way

Would this work? http://darcyclarke.me/development/detect-attribute-changes-with-jquery/ $.fn.watch = function(props, callback, timeout){ if(!timeout) timeout = 10; return this.each(function(){ var el = $(this), func = function(){ __check.call(this, el) }, data = { props: props.split(“,”), func: callback, vals: [] }; $.each(data.props, function(i) { data.vals[i] = el.css(data.props[i]); }); el.data(data); if (typeof (this.onpropertychange) == “object”){ el.bind(“propertychange”, callback); } else if ($.browser.mozilla){ el.bind(“DOMAttrModified”, …

Read more

Does the order of elements in a jQuery-wrapped set always match the order in which the elements appear in the markup?

Just been looking at this myself. jQuery does return things in document order as per the following article: http://docs.jquery.com/Release:jQuery_1.3.2 So, if you select some ids as such: $(“#id1, #id2, #id3”) Then they will be returned in the order they appear in the DOM, not necessarily in the order they are given. Its certainly worth being …

Read more

White spaces are required between publicId and systemId

The error message is actually correct if not obvious. It says that your DOCTYPE must have a SYSTEM identifier. I assume yours only has a public identifier. You’ll get the error with (for instance): <!DOCTYPE persistence PUBLIC “http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd”> You won’t with: <!DOCTYPE persistence PUBLIC “http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd” “”> Notice “” at the end in the second one …

Read more

async=true for css link tag

2021 edit: Original link moved – async CSS without JavaScript https://codepen.io/tigt/post/async-css-without-javascript “It seems this trick causes Chrome & Firefox to start the body earlier, and they simply don’t block for body stylesheets.” <head> <!–[if IE]> <link rel=”stylesheet” href=”style.css”> <![endif]–> </head> <body> <!–[if !IE]> –> <link rel=”stylesheet” href=”style.css” lazyload> <!– <![endif]–> </body> The article also contains …

Read more

Unloading/Removing content from an iFrame

The other solutions use innerHTML, which won’t always work in XHTML. They also only clear document.body (anything in the <head> is still present). Here is a solution that uses the DOM: var frame = document.getElementById(“myFrame”), frameDoc = frame.contentDocument || frame.contentWindow.document; frameDoc.removeChild(frameDoc.documentElement); This solution uses innerHTML: var frame = document.getElementById(“myFrame”), frameDoc = frame.contentDocument || frame.contentWindow.document; frameDoc.documentElement.innerHTML …

Read more