This is the following code which i tried on fiddle Jsfiddle code
<div data-role="navbar">
<ul>
<li><a href="#tab-1">Tab1</a></li>
<li><a href="#tab-2">Tab2</a></li>
<li><a href="#tab-3">Tab3</a></li>
</ul>
</div>
<div data-role="content">
<div id="tab-1">
<h2>Here is the first tab</h2>
</div>
<div id="tab-2">
<h2>Here is the second tab</h2>
</div>
<div id="tab-3">
<h2>Here is the third tab</h2>
</div>
</div>
How to do it?
Here is a sample code that use navbars as tabs.
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script>
var prevSelection = "tab1";
$("#navbar ul li").live("click",function(){
var newSelection = $(this).children("a").attr("data-tab-class");
$("."+prevSelection).addClass("ui-screen-hidden");
$("."+newSelection).removeClass("ui-screen-hidden");
prevSelection = newSelection;
});
</script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
<style>
.tab-content{
width:100%;
height:250px;
background-color:white;
border-bottom-left-radius:0.5em;
border-bottom-right-radius:0.5em;
}
.tab-content>div{
padding:5px;
}
</style>
</head>
<body>
<div data-role="page">
<div data-role="header">
<h1>My Title</h1>
</div><!-- /header -->
<div data-role="content">
<div data-role="navbar" id="navbar">
<ul>
<li><a href="#" class="ui-btn-active" data-tab-class="tab1">Tab1</a></li>
<li><a href="#" data-tab-class="tab2">Tab2</a></li>
<li><a href="#" data-tab-class="tab3">Tab3</a></li>
<li><a href="#" data-tab-class="tab4">Tab4</a></li>
</ul>
</div>
<div class="tab-content">
<div class="tab1">
Tab1
</div>
<div class="tab2 ui-screen-hidden">
Tab2
</div>
<div class="tab3 ui-screen-hidden">
Tab3
</div>
<div class="tab4 ui-screen-hidden">
Tab4
</div>
</div>
</div><!-- /content -->
</div><!-- /page -->
</body>
</html>
A demo - http://jsfiddle.net/m8wQM/
Let me know if it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With