开发者

jQuery Dependencies?

开发者 https://www.devze.com 2023-04-05 08:24 出处:网络
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.

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消