javascript - Event binding on dynamically created elements? -
I have a little code, where I'm looping through a selection box on a page and a The problem I have is that after the initial loop, any select box I add through Ajax or Dome will not be constrained. I have found this plugin (), but before I get 5k on my pages with another plugin, I want to see if anyone knows a way to do this, either jQuery With or from any other option should use jQuery 1.7 : Before , the recommended approach was to use: However, ... can be replaced with the following signature: Any parent who is present at the time of the incident is fine. For example I'm compulsive. Mouse On / Off P>
$ (staticAncestors) .on (eventName, dynamicChild, function () {});
$ (selector) .live (eventName, Function () {});
live was exempted in 1.7 in favor of
, and completely in 1.9 Was removed.
Live () Signature:
$ (selector) .live (eventName, function () {});
$ (document) .on (eventName, selector, function () {}) ; For example, if your page is dynamically creating elements with the class name
dosomething , then you will tie this event to a parent who already exists, often < Code> Document .
$ (document) .on ('mouseover mouseout', '.dosomething', function () {// what to do when you want to have mouseover and mouseout // elements Match that '.dosomething'});
$ ('.button'). ('Click', 'button', function () {// do something here});
& lt; Div class = "buttons" & gt; Will apply. & Lt ;! - & lt; Button & gt; That is dynamically generated and added here - & gt; & Lt; / Div & gt;
Comments
Post a Comment