tags:

views:

54

answers:

2

hi to every one i am new in jquery. i want to make an app using the drag and drop events in jquery.but i am NOT able to select a div among a set of divs with thesame name contained in a main div.please can anybody help me ? note these set of divs are generated dynamically ,getting the data from the database

A: 

To select a specific div, give it an ID.

<div class="container">
  <div>content</div>
  <div id="target">content</div>
</div>

$('#target') will let you get that specific div.

If you need to get a particular element in a list you can use the eq() function.

$('.container').eq(1)

will get the #target div

Dan Heberden
thanks for your answer.but the issue is the children divs are generated dynamically from the database so i want to use the mousedown event to getone of the generated divs within the main div <div class="suggestions"> inside here are the dynamically generated divs and i want the div click at that moment </div>
fon
Those kind of usage cases are a great help in getting you the right info - sometimes the answer isn't the path you might think, so having some more background as to _why_ you're trying to do something helps us out a bunch :) happy coding
Dan Heberden
A: 

It is just really tough to tell exactly what you need.

I sounds like you have elements that are generated dynamically in your javascript, and you are having trouble making those draggable.

I assume this means that you have successfully made other elements on the page draggable that were not added dynamically.

IF this is the case, before you add your new element to the page, just do the same draggable() call on it before you add it.

   // Create new element
var $newElement = $("<div class='suggestion'>I'm a suggestion</div>");

   // Make it draggable
$newElement.draggable();

   // Append it to your container
$newElement.appendTo('.suggestions');

If this is not what you mean, then please be very clear and detailed in your question. Please also add a code example, which often explains much. :o)

patrick dw
thanks very much .it worked this very helpful. once more thank your very much . great!!!!
fon
@fon - You're welcome. :o) If this answers your other question as well, you should probably delete that one so there isn't a duplicate.
patrick dw