> I would have thought that jQuery would repeat the above process if I
> created another div with a class of "box" below the previous one.

I can understand that, since it's the way CSS rules work. If you
declare a CSS rule p.big { font-size: 200% }  then any p with class
big will have bigger text no matter when it is added to the document.

However, jQuery is not declarative, it is procedural. It just uses CSS
selector syntax to select nodes. The selection happens at the point
where the jQuery code is executed, in your case in the ready() handler
right after the document loads. Anything added after that isn't
affected by the code that was executed earlier.

Like MorningZ says, you can use the LiveQuery plugin to do what you
describe. That's especially useful when you're inserting HTML into a
page and not quite sure what's in it, such as the response from an
AJAX transaction. If I am inserting an element and I know it needs a
handler, I prefer to attach the handler then because it avoids the
overhead of LiveQuery.

Reply via email to