tags:

views:

35

answers:

2

i have made a ajax request and the verious rows gotten i echo each into a dynamically created the div.now i want to bind a event to each of these divs like say e.g mousedown() .. do something but i am not able to access any of the divs. plis can any one help me on that. thanks in advance

+1  A: 

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.

Nick Craver
A: 

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...)

Syom