HTMLElement: draggable プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
draggable
は HTMLElement
インターフェイスのプロパティで、要素がドラッグ可能かどうかを示す論理値プリミティブを取得または設定します。
これは、dragableHTML グローバル属性の値を反映します。
It reflects the value of the draggable
HTML global attribute.
値
論理値プリミティブで、要素がドラッグ可能であれば true
、そうでなければ false
です。
例
次の例は、スクリプトによる要素のドラッグ機能を有効または無効にする方法を示しています。
js
const draggableElement = document.querySelector(".draggable-element");
const notDraggableElement = document.querySelector(".not-draggable-element");
// 対象とする要素のドラッグ機能を有効にする
if (!draggableElement.draggable) {
draggableElement.draggable = true;
}
// 対象とする要素のドラッグ機能を無効にする
if (notDraggableElement.draggable) {
notDraggableElement.draggable = false;
}
仕様書
Specification |
---|
HTML # dom-draggable |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
draggable |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
関連情報
- HTML の
draggable
グローバル属性 - HTML のドラッグ&ドロップ API の概要