Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
<body>

  <div id="container">

    <ul class="tabs">
      <li><a href="https://www.bronco.co.uk/uploads/append-post.html?dest=seo" data-append="#seo" data-current>SEO</a></li>
      <li><a href="https://www.bronco.co.uk/uploads/append-post.html?dest=web" data-append="#web">Web</a></li>
      <li><a href="https://www.bronco.co.uk/uploads/append-post.html?dest=ppc" data-append="#ppc">PPC</a></li>
    </ul>

    <div class="content" id="seo">
      SEO Content
    </div>

  </div>

</body>
</html>
              
            
!

CSS

              
                ul {display:flex; margin:0 0 20px 0; padding:0; gap:10px;}
li {list-style:none; border:1px solid #000; padding:10px; }
              
            
!

JS

              
                $('body').on('click','a[data-replace], [data-replace] a, a[data-append]', function(ev){

  ev.preventDefault();
  ev.stopPropagation();

  // get clicked element
  var clicked = $(this);

  // get destination url
  var destination = $(clicked).attr('href');

  // determine if replacing or appending
  var state = ($(clicked)[0].hasAttribute('data-append') || $(clicked).closest('[data-append]').length > 0) ? 'append' : 'replace';

  // get id of content to append
  var id = ($(clicked)[0].hasAttribute('data-append') || $(clicked).closest('[data-append]').length > 0) ? $(clicked).data('append') : null;
  
  // get previous 'current' tab
  var tabs = $(clicked).closest('.tabs');
  var previous_current = $(tabs).find('[data-current]');

  // if requested content doesn't exist, then continue to AJAX request
  if($(id).length == 0){

    // disable function on double click
    if(!window.click){

      window.click = true;

      // get # of destination_container
      var destination_container = ($(clicked).data(state)) ? $(clicked).data(state) : $(clicked).closest('[data-' + state + ']').data(state);

      // AJAX request
      $.get(destination, function(data){
        
        // replace content
        if(state == 'replace'){

          // filter to required html
          var new_html = $(data).filter(destination_container).html();

          // replace container with new html
          $(destination_container).html(new_html);

          // append content
        }else if(state == 'append'){

          // filter to required html
          var new_html = $(data).find(destination_container)[0].outerHTML;

          // append container with new html
          $('#' + $(data).find(destination_container).parent().attr('id')).append(new_html);

          // update tab state here (if required)
          updateTabContent(previous_current,clicked);

        }

        // reset click
        window.click = false;

      });

    }

    // if content already appended
  }else if(state == 'append'){

    // show this content
    $(id).show();

    // update tab state here (if required)
    updateTabContent(previous_current,clicked);

  }

});

function updateTabContent(previous_current,clicked){

  // hide previous current child
  $($(previous_current).data('append')).hide();

  // update current tab
  $(previous_current).removeAttr('data-current');
  $(clicked).attr('data-current',true);

  // if has tab mobile view
  if($(clicked).closest('.tabs--mobile').length > 0){
    var toggle = $(clicked).closest('.tabs--mobile').prev('.tabs--mobile-toggle');
    // update tab mobile
    $(toggle).find('span').html($(clicked).html());
    // close tab mobile
    if($(toggle).is(':visible')){
      $(toggle).trigger('click');
    }
  }

  }
              
            
!
999px

Console