How to capture touchend coordinates?

You need to store the values on touchmove and read it in touchend. var lastMove = null; // Save the touchstart to always have a position div.addEvent(‘touchstart’, function(event) { lastMove = event; }); // Override with touchmove, which is triggered only on move div.addEvent(‘touchmove’, function(event) { lastMove = event; });

Can one replace xhr.onreadystatechange with xhr.onload for AJAX calls?

maybe you take a look at this one and a look at W3C: XMLHttpRequest it’s the same if your browser supports xhr.onload. Requires XMLHttpRequest 2) You can also write a wrapping function that emulates xhr.onload if it’s not present. (I think you need to override XMLHttpRequest.prototype.onload = function(args){//calling onreadystatechanges somehow}). If you only support modern … Read more

Cross domain iframe issue

If you don’t have control over the framed site, you cannot circumvent the cross-domain policy. If you have control over both sites, you can use the postMessage method to transfer data across different domains. A very basic example: // framed.htm: window.onmessage = function(event) { event.source.postMessage(document.body.innerHTML, event.origin); }; // Main page: window.onmessage = function(event) { alert(event.data); … Read more

Why is jQuery so widely adopted versus other Javascript frameworks? [closed]

That’s an odd question… I get the impression that… you are very familiar with mootools and take full advantage of its OOP model, making your code easier to manage and support already. you realise that jQuery’s purpose is somewhat different and tweaked towards DOM manipulation and AJAX and that mootools does do everything jQuery does … Read more

Simplest way of getting the number of decimals in a number in JavaScript [duplicate]

Number.prototype.countDecimals = function () { if(Math.floor(this.valueOf()) === this.valueOf()) return 0; return this.toString().split(“.”)[1].length || 0; } When bound to the prototype, this allows you to get the decimal count (countDecimals();) directly from a number variable. E.G. var x = 23.453453453; x.countDecimals(); // 9 It works by converting the number to a string, splitting at the . … Read more

CSS selector for targeting only immediate children and not other identical descendants

ul > li only does the immediate children. So, for example, to do only the top level list elements you could use: #parent > li Note: this isn’t supported on IE6. The common workaround for backwards compatibility is to do something like this: #parent li { /* style appropriately */ } #parent li li { … Read more