- From: Michaël Rouges <michael.rouges@gmail.com>
- Date: Sat, 18 May 2013 12:03:53 +0200
- To: public-html@w3.org
- Message-ID: <CAMNVKQFF0Jarp1+2_yR4oXToNSq_83N5_S=xdgenBwDtFQuMng@mail.gmail.com>
Hello everyone, Faced with the need to extend a DOM builder for one of my scripts, I thought about a feature that would be very useful, as more and more sites are going through dynamic content systems. The idea is being able to add events to a collection of nodes, existing and future, for a given selector. This would avoid costly solutions like this: (function () { var catchClickOnAnchors; catchClickOnAnchors = function(event){ var anchors, iterator, length; anchors = document.getElementsByTagName('a'); for (; iterator < length; iterator += 1) { anchors[iterator].addEventListener('click', function (event) { console.log('Caught click'); event.preventDefault(); event.returnValue = false; return false; }, false); } }; catchClickOnAnchors(); document.addEventListener('DOMSubtreeModified', catchClickOnAnchors, false); }()); Suggested design : window.addQueryEventListener = function (querySelector, event, listener, useCapture) {}; window.removeQueryEventListener = function (querySelector, event, listener, useCapture) {}; Well, that's all for now, if you have any questions, do not hesitate to contact me, I will answer with pleasure. Cordially, Michaël Rouges
Received on Saturday, 18 May 2013 10:04:20 UTC