2

I want to do something like the following(hopefully you get the idea):

$('.timepickersec').live(function() {
        $(this).jtimepicker();
    });

That is,for each new created .timepickersec in the future,bind the jtimepicker on it.

But the above is not working, does $.live has such a feature?

compile-fan
  • 16,885
  • 22
  • 59
  • 73
  • 1
    This a possible duplicate of http://stackoverflow.com/questions/2548479/jquery-live-on-load-event and short answer no this is not possible. – Amir Raminfar Mar 26 '11 at 05:17
  • Well you can bind a custom event using [`live`](http://api.jquery.com/live/) and trigger it using [`trigger`](http://api.jquery.com/trigger/) whenever you create something with class `timepickersec` – Jishnu A P Mar 26 '11 at 05:29

2 Answers2

3

Other way with event : DOMNodeInserted to detect when a new element is inserted

 $(document).bind('DOMNodeInserted', function(event) {
      alert('inserted ' + event.target.nodeName + // new node
            ' in ' + event.relatedNode.nodeName); // parent
});
Elium1984
  • 154
  • 3
  • 13
0

I believe you are looking for the livequery plugin. Under the hood it will do setIntervals to check for new elements. Now you can sometimes also achieve this same effect using live mousemove event. In the callback check to see if the element has already been activated - and activate it appropriately.

Josiah Ruddell
  • 29,697
  • 8
  • 65
  • 67