Say I have a jquery function that takes an element: <div id="hello"></div>
and maninpulates the DOM and appends lots of new elements onto it, e.g.
<div id="hello"></div>
*run jquery fun开发者_JS百科ction*
<div id="hello"><div id="a"></div><div id="b"></div></div>
Ive encountered the problem that trying to select $('#a')
or $('#b')
on 'document.ready' returns 0 items as the first function obviously hasnt finished yet.
What are my options?
I've tried using $.live()
to some success.
jQuery 'delegate' is the preferred method for binding events to dynamically created elements. See the documentation for reasons why.
http://api.jquery.com/delegate/
精彩评论