Help us understand the problem. What is going on with this article?

ontouchxxxxxは存在しない

More than 1 year has passed since last update.

ontouchstart, ontouchmove, ontouchendは存在しない。

console.log(onmousedown); // => null
console.log(ontouchstart); // => Uncaught Error: 'ontouchstart' is not defined

当然、代入してもタッチイベントは取れない。

// マウスで左クリックする時のイベント
addEventListener('mousedown', function() { console.log('new mouse'); });

// 古いやり方(非推奨だが、可能)
onmousedown = function() { console.log('old mouse'); };


// スマホなどでタップする時のイベント
addEventListener('touchstart', function() { console.log('new touch'); });

// 古いやり方も可能かと思いきや、不 可 能
ontouchstart = function() { console.log('old touch'); };

ちなみにこの例では一貫してグローバルオブジェクト(window)だったが、
documentでも個別のHTML要素でも同様に無効である。

たとえ書き捨て目的でもサボらずaddEventListenerを使おう。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away