I am trying to learn and still sucking at jquery and javascript and I can't figure out how to really phrase this right to get any useful answers by searching, so here goes.
I have a box with three divs serving as tabs. When each tab is clicked it loads different content into another div. Simple. The below code works, functionality-wise, but I have a feeling it's not very practical or efficient, plus I need to be able to use HTML and PHP inside the tab content which I can't seem to figure out how to accomplish.
My two questions are, is there a way to combine this into a simpler function? And, what is the best way of going about loading HTML and PHP content into the div when each tab is clicked?
HTML:
<div id="single-space-details">
<div id="space-details-tabs">
<div class="space-details-tab one">
Description
<a href="javascript:void(0);" class="linkwrap"></a>
</div>
<div class="space-details-tab two">
Specs
<a href="javascript:void(0);" class="linkwrap"></a>
</div>
<div class="space-details-tab contact three">
Contact
<a href="javascript:void(0);" class="linkwrap"></a>
</div>
<div style="clear:both;"></div>
</div>
<div id="single-space-tab-content">
Default Tab one content
</div>
<div style="clear:both;"></div>
</div>
SCRIPT:
<script>
$(function() {
$('.space-details-tab.one').click(function() {
var tabcontent = "Tab 1 content";
document.getElementById('single-space-tab-content').innerHTML = tabcontent;
$('.space-details-tab').css("background-color","#eee");
$(this).css("background-color","#fff");
});
});
$(function() {
$('.space-details-tab.two').click(function() {
var tabcontent = "Second Tab Test Content";
document.getElementById('single-space-tab-content').innerHTML = tabcontent;
$('.space-details-tab').css("background-color","#eee");
$(this).css("background-color","#fff");
});
});
$(function() {
$('.space-details-tab.three').click(function() {
var tabcontent = "Tab 3 Test Content";
document.getElementById('single-space-tab-content').innerHTML = tabcontent;
$('.space-details-tab').css("background-color","#eee");
$(this).css("background-color","#fff");
});
});
</script>