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:

  1. apply id div , reference way
  2. 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

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -