2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

buttonがdisabled時にtitle属性を表示させる方法

Posted at

問題

ある条件の時にbuttonをdisabledして使用不可にした際に, 使用不可である理由をtitle属性を用いたtooltipで表示したい時がある. しかし, bottonをdisabledさせると, マウスホバー時のイベントが無効になってしまうため, マウスホバーをさせてもtooltipが表示されないことがある.

解決法

1. pointer-events: autoを与える

<button disabled style='pointer-events: auto' 
title='ツールチップの内容' >
  ボタン
</button>

2. 対象をdivタグでくくり, それにtitle属性を与える

<div title='ツールチップの内容'>
  <button disabled >ボタン</button>
</div>

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?