1

Do any projects exist that implement the follow proposal?

http://www.w3.org/2008/webapps/wiki/Selector-based_Mutation_Events

Jimmie Tyrrell
  • 1,479
  • 3
  • 12
  • 32
  • You could try mutation observers. Although they will listen to every added element, they have much better performance than mutation events. [Demo](http://jsfiddle.net/Lu0tvced/1/) – Oriol Aug 11 '14 at 19:35
  • As stated in the original question: `The DOM I'm modifying however is quite complex, so I don't want to listen to *every* node that's added for performance reasons.` But thank you for the suggestion – Jimmie Tyrrell Aug 11 '14 at 19:51

1 Answers1

-1

Here's a better way that allows you to listen for any selector with actual events, vs dirty checking, mutation listening, and other non-performant ideas: https://github.com/csuwildcat/SelectorListener (it was also used as the basis of this highly rated solution: Alternative to DOMNodeInserted)

Here are a few examples:

// Listening for attribute value matches? Child's play.
document.addSelectorListener('.foo[bar="boom"]', function(){ ... });

// Matching elements on hashchange can be annoying, let's make it stupid simple
document.addSelectorListener('*:target', function(event){
  alert('The hash-targeted element is:' + event.target);
});

// How about a more performant way to listen for custom tooltip nodes document wide?
document.addSelectorListener('.tooltip:hover', function(){ ... });


/*** Now that we have the new CSS 4 Selector spec, let's see what we can do: ***/

// Working with HTML5 sliders just got even easier
document.querySelector('#RandomForm').addSelectorListener('slider:out-of-range', function(){
  alert('Your slider value is now out of range! Oh noes!');
Community
  • 1
  • 1
csuwldcat
  • 8,021
  • 2
  • 37
  • 32