LoginSignup
0
0

More than 5 years have passed since last update.

interactive tabindex='-1'

Last updated at Posted at 2019-04-15

-demo https://codepen.io/gnjo/pen/ZZXrGY
-delete keyを押すと自身を削除する。

///core
 el.setAttribute('tabindex','-1') //interactive-able

let fn={}
fn.deleteMe=function(el){
 let is={}; 
 is.element=function(o){return !!(o && o.nodeType === 1)}
 ;
 if(!is.element(el)){
  console.log('delemteMe not element',el)
  return el;
 }
 el.setAttribute('tabindex','-1') //interactive-able
 el.style.outline='none'
 el.onkeydown=(e)=>{
  if(e.which===46) e.target.remove();//46 delete
 }
 return el;
}


let a=document.querySelector('#a')
a.onkeydown=(e)=>{
 console.log(e.type,e)
}
let b=document.querySelector('#b')
fn.deleteMe(b)///////
<img id="a" src="https://i.imgur.com/KkuF4ga.png">

<img id="b" src="https://i.imgur.com/KkuF4ga.png">
0
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
0
0