Tabbed content using jQuery

  Previous article Next article  

Tabbed content is a great way to have much content on a page (which might be SEO-friendly). I will show you how easy it is to add them to a CMS Made Simple template.

  How to use

This feature uses jQuery, so to start you need to call the jQuery library in your template. If you already have it there because another module uses it, you don't need to add it twice!

Add this little jQuery code to your CMSMS template:

<script src="//"></script>

<script type="text/javascript">
  $(function () {
    var tabContainers = $('div#tabs > div');
    $('div#tabs ul#tabNavigation a').click(function () {
      $('div#tabs ul#tabNavigation a').removeClass('selected');
      return false;
    } ).filter(':first').click();
  } );

In your template you can create content blocks and the tabs like this:

{content assign='content_tab1' label='Content Tab 1'}
{content block='content_tab2' assign='content_tab2' label='Content Tab 2'}
{content block='content_tab3' assign='content_tab3' label='Content Tab 3'}

<div id="tabs">

  <ul id="tabNavigation">
    <li class="tab-1"><a href="#tab-1"> 1 </a></li>
    <li class="tab-2"><a href="#tab-2"> 2 </a></li>
    <li class="tab-3"><a href="#tab-3"> 3 </a></li>
  <div id="tab-1">{$content_tab1}</div>
  <div id="tab-2">{$content_tab2}</div>
  <div id="tab-3">{$content_tab3}</div>


But you can also put hardcoded content or global content blocks in the tabs...

Sample stylesheet:

ul#tabNavigation {
 padding: 0 0 0 10px;
  margin: 0;
  width: 99%;
  height: 22px;

ul#tabNavigation li {
 height: 22px;
  float: left;
  margin: 0 0 0 10px;
  list-style-type: none;

ul#tabNavigation li a {
 height: 9px;
  padding: 3px 3px 9px 3px;
  text-decoration: none;
  color: #333;
 display: block;
  border: #ccc solid 1px;
 font-size: 10px;
  box-sizing: content-box;

ul#tabNavigation li a.selected {
 border-top: #999 solid 1px;
 border-left: #999 solid 1px;
 border-bottom: #fff solid 1px;
 border-right: #999 solid 1px;
 outline: none;

#tab-1,#tab-2,#tab-3 {
 height: 150px;
  padding: 10px;
  border: #ccc solid 1px;

  Working example

Buy Me A Coffee

  Comment Form


Click here to open the form



Buy Me A Coffee

CMS Made Simple - Tutorials, Tips and Tricks - CMSMS

Tabbed content using jQuery

  Article optimized for CMSMS 2.x

  Last tested in: CMSMS 2.2.19
  Last updated: 19-05-2018
  Comments: 2

Buy Me A Coffee


Ads help me to help you! Thanks!

Ads help me to help you! Buy products from these advertisers!