compile-fan
compile-fan

Reputation: 17625

jQuery's live without an event?

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?

Upvotes: 2

Views: 3383

Answers (2)

Elium1984
Elium1984

Reputation: 154

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
});

Upvotes: 3

Josiah Ruddell
Josiah Ruddell

Reputation: 29831

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.

Upvotes: 0

Related Questions