asp.net.ph

Skip Navigation Links

ondragstart Event


Fires on the source object when the user first starts to drag a text selection or selected object.

Syntax

Inline <element ondragstart = "handler" ... >
Script object.ondragstart = handler

Remarks

Bubbles Yes
Cancels Yes
To invoke Drag the selected text or object.
Default action Calls the associated event handler.

The ondragstart event is the first to fire when a drag procedure is initiated. It is essential to every drag operation, yet is just one of several source events in the data-transfer object model. Source events use the setData method of the dataTransfer object to provide information about data being transferred. The list of source events includes:

Event Object Properties

While event handlers in the Document Object Model do not receive parameters directly, the handler can query the event object for data.

Event Object Properties


Example

This example detects the tagName of the object from which the ondragstart event has originated. Because the event bubbles, it can be handled at the BODY level.

<body ondragstart="
  alert('You have dragged something from the '+ 
  event.srcElement.tagName)">
<div align="center">
<h5>Select and drag any text on this document.</h5>
<input type=text value="This is a textbox" readOnly>
<br><br>
<span>This is a span</span>
<br><br>
<textarea readOnly>This is a textarea</textarea>
</div>
</body>

 Show me 


This example shows the order of event firing for drag-and-drop events.

<head>
<script language="JavaScript">
var oNewOption;            
// Code for dynamically adding options to a select.
function ShowResults ( ) {
// Information about the events
// and what object fired them.
arg = event.type + " fired by " +
  event.srcElement.id;  
oNewOption = new Option();
oNewOption.text = arg;
theResults.add(oNewOption,0);}
</script>
<head>

<body>
<div align="center">
<p>Source events are wired up to this text box.</p>
<input id=theSource value="Text to Drag"
  ondragstart="ShowResults()"
  ondrag="ShowResults()"
  ondragend="ShowResults()">
<br>
<p>Target events are bound to this text box.</p>
<input id=theTarget value="Drag Destination"
  ondragenter="ShowResults()"
  ondragover="ShowResults()"
  ondragleave="ShowResults()"
  ondrop="ShowResults()">
<br>
<select id="theResults" size=15>
  <option>List of events fired, 
    starting with the most recent</select>
</div>
</body>

This feature requires Microsoft® Internet Explorer® 5.0 or later.

 Show me 

See Also

Data Transfer Overview, onbeforecut, onbeforecopy, oncut, oncopy, ondrag, ondragend


Need a break ?
Suggested Reading

Check out related books at Amazon

© 2025 Reynald Nuñez and asp.net.ph.

If you have any question, comment or suggestion,
please send us a note