trap deliver button content

by ian_smithz

HTML

<div class="lb-DataHolder-Wrap" role="dialog" tabindex="-1" aria-hidden="false" style="width: 936px; height: 370px; top: 37px; margin-left: auto; margin-right: auto;">
  <div class="lb-close-bl js--close-Lightbox" style="width: 936px; margin-left: auto; margin-right: auto;">
    <button class="lb-btn-cancel"><span class="icon-cancel-text">CLOSE</span><span class="icon-cancel"></span></button>
  </div>
  <div class="lb-DataHolder js--lightbox" role="document" style="width: 936px; background-color: transparent;">
   

    <input id="shippingGroupType" type="hidden" value="WAREHOUSE">
    <div class="wrp wrp__modal atb__top">
      <div class="inner">
        <div class="item-added bulk-saving-popup">
          <div class="row">
            <div class="lg-4 md-4 sm-hide cols">
              <div class="">
                <span class="icon-ok icon--round icon--big"></span>
              </div>
            </div>
            <div class="lg-19 lg-offset-0 md-19 md-offset-0 sm-22 sm-offset-1 cols">
              <div class="row" id="overlayGeneralText">

                <h2>1 x No Nonsense GP Silicone White 310ml Pack of 12 added to basket <span class="h2">for delivery</span></h2>

              </div>
            </div>
          </div>

          <div class="row">
            <div class="lg-19 lg-offset-4 md-18 md-offset-4 sm-24">

            </div>
          </div>

          <div class="row">
            <div class="lg-19 lg-offset-4 md-18 md-offset-4 sm-24" id="overlayDeliveryDescription">
              <ul>
                <li>Next Day Delivery 7 days a week (<a href="/help/delivery" target="_blank">restrictions apply</a>)</li>
                <li>Free weekday Delivery on orders over £50 </li>
              </ul>
              <input id="collectionQuantity" type="hidden" value="">
              <input id="continueShoppingUrl" type="hidden" value="/c/sealants-adhesives/general-purpose-sealants/cat850048">

              <div id="checkout_now" class="lg-10 md-12...

JavaScript

var trapFocus = function(elem) {

  var tabbable = elem.find('a[href], button:not([disabled]), area[href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), iframe, object, embed, *[tabindex], *[contenteditable]').filter(':visible');
  var firstTabbable = tabbable.first();
  
  console.log('firstTabbable is ' + firstTabbable);
  
  var lastTabbable = tabbable.last();
  
console.log('lastTabbable is ' + lastTabbable);
  
console.log(tabbable);

  //redirect last tab to first tabbable
  lastTabbable.on('keydown', function(e) {
    if ((e.which === 9 && !e.shiftKey)) {
      e.preventDefault();
      firstTabbable.focus();
    }
  });

  // redirect first shift+tab to last tabbable
  firstTabbable.on('keydown', function(e) {
    if ((e.which === 9 && e.shiftKey)) {
      e.preventDefault();
      lastTabbable.focus();
    }
  });

  if ($('.lb-DataHolder .btn--primary').length) {
    $('.lb-DataHolder .btn--primary').focus();
  } else if ($('.lb-DataHolder .btn').length) {
    $('.lb-DataHolder .btn').first().focus(); // for bulk save view offer modal
  } else {
    $('.lb-btn-cancel').focus();
  }


  // allow escape key to close inside modal 
  elem.on('keyup', function(e) {
    if (e.keyCode === 27) {
      elem.hide();
    }
  });
};

trapFocus($('.lb-DataHolder-Wrap'));