Reputation: 265
I have made a ajax request and the various rows gotten I echo each into a dynamically created the div. Now I want to bind a event to each of these divs like mousedown() .. do something but I am not able to access any of the divs. Please can any one help me with that?
Upvotes: 0
Views: 1087
Reputation: 101811
if your using jQuery 1.7+ you should use .on() or .delegate() as .live() is depreciated.
jQuery("table").on("click", "tr", function(event){});
Upvotes: 3
Reputation: 23141
and another solution, than .live()
You can just load the jquery function dinamycally, in your ayax request. it's not usefull in small tasks, but in large projects it can be very usefull (from my practice...)
Upvotes: 0
Reputation: 630349
You can use .live()
, like this:
$(".myDivClass").live('mousedown', function() {
alert('Your mouse is down!');
});
You can view a quick demo here
It doesn't bind an event to those new divs, it just executes the function/handler whenever a mousedown
happens in an element matching that class (determined via bubbling), getting the effect you want...as if you bound the handler to each new div that appears.
Upvotes: 2