Created
November 11, 2011 18:36
-
-
Save jaydson/1358813 to your computer and use it in GitHub Desktop.
How to observe when an element is created
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var readyElement = (function(){ | |
| return { | |
| observe : function(id,callback){ | |
| var interval = setInterval(function(){ | |
| if(document.getElementById(id)){ | |
| callback(document.getElementById(id)); | |
| clearInterval(interval); | |
| } | |
| },60); | |
| } | |
| } | |
| })(); | |
| readyElement.observe('my_awesome_new_element',function(el){ console.log(el) }); |
Author
Cool, sounds like a good micro-solution.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yeah the event is still a draft. I'd do the fallback thing as well. If you want to be more flexible, you can add options for the interval time and input selector format (id, class, element name, etc.) :)