Home    Articles

 

How to make multiple elements with same id draggable in jquery

 

Using the same id on multiple elements is not a good choise.
The id should be unique for each element.
multiple-classes-draggable
If you use the id as a selector and you have multiple elements with the same id, the first element will always be used.
The solution is the use classes and you can keep same id on multiple elements.
You can give a class to an unlimited elements.
Example:

<div id="same_id" class="my_draggable_element">
    <p>Drag me around</p>
  </div>
  <div id="same_id" class="my_draggable_element">
    <p>Drag me around</p>
  </div>

 $(".my_draggable_element").draggable();

JsFiddle Example

by