简体   繁体   中英

JQuery Tabs : Can the tabs and content be in different containers?

I am trying to place Tabs in the header, but want them to control the content in an adjacent containers. Is this possible if the both Tabs+Content are not nested within the same DIV tags?

$(function() {
    $( ".tabs" ).tabs
});
<header>
    <div class="tabs">
        <ul>
            <li><a href="#links">Links</a></li>
            <li><a href="#filters">Filter</a></li>
        </ul>
    </div>
</header>

<div id="container" class="tabs">

    <div id="links">
       Stuff in here
    </div>

    <div id="filters">
       Stuff in here
    </div>

</div>

Check below example hope you are expecting similar option.

HTML

<div id="pagewraper">
  <header>
    <ul class="menu">
      <li><a href="#tabs-1">Menu one</a></li>
      <li><a href="#tabs-2">Menu two</a></li>
      <li><a href="#tabs-3">Menu three</a></li>
    </ul>
  </header>

  <div id="container">
    <div id="tabs-1">
      <p>Tab one content</p>
    </div>
    <div id="tabs-2">
      <p>Tab two content</p>
    </div>
    <div id="tabs-3">
      <p>Tab three content</p>
    </div>
  </div>
</div>

CSS

ul.menu{
    margin:0;
    padding:0;
}
ul.menu li{
   display: inline-block;
}
ul.menu li a{
   display: block;
    padding: 10px;
    background: #333;
    color: #fff;
}

jQuery

$( "#pagewraper" ).tabs();

JSFIDDLE DEMO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM