javascript - Connection between arbitrary runtime script element and DOM element -
this has been troubling me lately, , i've found related questions (like here , here), they're not quite i'm looking , seems there should fear i'm missing something.
it common pattern (of mine, @ least) ajax request returns snippet of html along bit of javascript meant operate on (or initialize) html in way. i'd able reference html being inserted directly javascript, like:
<div class="fancy_div"> <select></select> </div> <script type="text/javascript"> myalreadyloadedlibraryfunction(justinserteddivabove); </script> but instead understanding script block pretty ignorant of position on page, , cannot reference element directly, relatively.
what i've seen suggested here either:
- apply id div , reference way
- with jquery, use class iterate on divs of class
for #1, guess seems overkill generate unique id element may need referenced relatively going forward.
for #2, seems huge overkill iterate on elements in page of class
i in process of moving away prototype , more jquery, , i'm not intimate jquery style (but interested).
i may over-thinking this, or missing something, or misguided in pattern, or need nudge - time!
unless you're planning hundreds of thousands of times, creating new unique id use grabbing element won't make major performance impact. in fact, fastest method.
Comments
Post a Comment