I'd like my GreaseMonkey script to run a function whenever elements with a specific class are inserted into a page. What's the most idiomatic way of doing that?
If it helps, it's a <select>
element that is being inserted.
I'd like my GreaseMonkey script to run a function whenever elements with a specific class are inserted into a page. What's the most idiomatic way of doing that?
If it helps, it's a <select>
element that is being inserted.
You can use DOMNodeInserted
This event is fired whether using DOM methods (appendChild et al) or innerHTML, and is fired in Opera as well, so it won't break portability of your userscript (if you care). Check out http://www.quirksmode.org/dom/events/tests/DOMtree.html
If you specify an argument for the function that is being called on DOMNodeInserted, that argument's 'target' property will be the node that a node is being inserted into. So, you could check the nodeType of that to see if it is the type you are looking for. DOMNode also has a className property you could check on. http://www.howtocreate.co.uk/tutorials/javascript/domstructure