Example of the clearData Method

The example demonstrates how to use event.dataTransfer.clearData('Text') to clear the clipboard.

In this example, the string "This text should be cleared" is passed in the setData method. The clearData method clears it. It also clears the text being dragged so that it does not appear in the DIV upon completion of the data transfer operation. This method is particularly useful for selectively removing data formats when multiple formats are specified.

Highlight the green text. Then drag it and drop it over the magenta DIV.

drag this text

Drop the text below. Null will appear when the clearData method is successfully invoked.




[Right-click and choose View Source from the shortcut menu.]

© 2007 Microsoft Corporation. All rights reserved. Terms of use.