Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
  <div class="one" tabindex="0">
    <button>Button 1</button>
    <button>Button 2</button>
  </div>
  <div class="two" tabindex="0">
    <button>Button 3</button>
    <button>Button 4</button>
  </div>
  
  <output></output>
  
</body>
</html>
 
body {
  font-family: Arial, sans-serif;
  padding: 20px;
  text-align: center;
}
button {
  margin-bottom: 20px;
}
output {
  display: block;
  font-weight: bold;
  line-height: 1.5;
}
 
console.clear();
var one = document.querySelector('.one'),
    two = document.querySelector('.two'),
    btn1 = document.querySelector('button'),
    btn2 = document.querySelectorAll('button')[1],
    btn3 = document.querySelectorAll('button')[2],
    btn4 = document.querySelectorAll('button')[3],
    op = document.querySelector('output');
one.addEventListener('focusin', function (e) {
  op.innerHTML += 'Element inside DIV ONE has been focused<br>';
}, false);
one.addEventListener('focusout', function (e) {
  op.innerHTML += 'Element inside DIV ONE has lost focus<br>';
}, false);
two.addEventListener('focusin', function (e) {
  op.innerHTML += 'Element inside DIV TWO has been focused<br>';
}, false);
two.addEventListener('focusout', function (e) {
  op.innerHTML += 'Element inside DIV TWO has lost focus<br>';
}, false);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
ImpressiveWebspro
0viewers