Search code examples
javascripthtmldraggable

Access the `draggable` attribute with javascript


So the question is : How can you do that ? I want to change the draggable attribute to "false" so the element that was previously draggable will lose this property.

I will give you a div so you will have something to start with :

     <div id="div1"  draggable="true" ondragstart="drag(event) "onDblClick="edit('div1')">
     </div>

Solution

  • document.getElementById('div1').setAttribute('draggable', false);
    

    OR

    var elem = document.getElementById('div1');
    elem.setAttribute('draggable', false);
    

    If you want the attribute totally gone use;

    elem.removeAttribute('dragable');