Q:

focus to button which is where it click from when click

I am new in jquery and now having some trouble with it. 
I have several buttons and after click button, the layer(div) is display.
When click the "ok"button, the layer close with focus to button which is when clicked.
This is what I tried so far, but I am having trouble with focus event. 
What do I need to add the code ? 
Please help.

$(function($) {
  $('.btn').click(function() { 
    $('.popup').show().attr('tabindex', '0').focus();
  });
  $('.layer_close').click(function() {
    $('.popup').hide().removeAttr('tabindex');
  });
});
.popup {  display: none}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btn" id="start1">start date</button>
<button class="btn" id="end1">end date</button><br>
 
<button class="btn" id="start2">start date</button>
<button class="btn" id="end2">end date</button><br>
  
<button class="btn" id="start3">start date</button>
<button class="btn" id="end3">end date</button><br>
 

<div class="popup">
 <input type="radio" id="n1" name="rr"><label for="n1">1</label>
 <input type="radio" id="n2" name="rr"><label for="n2">2</label>
 <input type="radio" id="n3" name="rr"><label for="n3">3</label>
   <button class="layer_close" type="button">ok</button>
</div>

A:

I am assuming you want to return the focus to the button that was clicked (and which caused the popup to open)
So the way to do this is to hold a reference to the clicked button in a variable so you can later use it to bring the focus to that element.

$(function($) {
  var openerButton;
  $('.btn').click(function() { 
    openerButton = this;
    $('.popup').show().attr('tabindex', '0').focus();
  });
  $('.layer_close').click(function() {
    $('.popup').hide().removeAttr('tabindex');
    openerButton.focus();
  });
});
.popup {  display: none}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button class="btn" id="start1">start date</button>
<button class="btn" id="end1">end date</button><br>
 
<button class="btn" id="start2">start date</button>
<button class="btn" id="end2">end date</button><br>
  
<button class="btn" id="start3">start date</button>
<button class="btn" id="end3">end date</button><br>
 

<div class="popup">
 <input type="radio" id="n1" name="rr"><label for="n1">1</label>
 <input type="radio" id="n2" name="rr"><label for="n2">2</label>
 <input type="radio" id="n3" name="rr"><label for="n3">3</label>
   <button class="layer_close" type="button">ok</button>
</div>

