Yesterday I had an issue where a .on('click')
event handler I was assigning wasn't working right. Turns out it's because I was was trying to apply that .on('click')
before that element existed in the DOM, because it was being loaded via AJAX, and therefore didn't exist yet when the document.ready()
got to that point.
I solved it with an awkward workaround, but my question is, if I were to put a <script>
tag IN the ajax loaded content and another document.ready()
within that, would that second document.ready()
be parsed ONLY once that ajax content is done being loaded? In other words, does it consider that separately loaded ajax content to be another document
, and if so, does having another document.ready()
within that ajax-loaded HTML work the way I think it does?
Alternatively; what would be a better way to handle this situation? (needing to attach an event listener to a DOM element that doesn't yet exist on document.ready()
)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…