Прежде всего, ваш HTML-код недействителен - вы закрываете <li>
элементы списка с тегами </div>
.Вы также забыли закрыть кавычку, окружающую значение атрибута #content
элемента *1003*.
Исходный код JavaScript не особенно эффективен, поэтому мы могли бы его переписать.Используя этот код, вам не нужно, чтобы каждое содержимое вкладки имело атрибут class
, что, безусловно, немного облегчает HTML:
// Select all of the tab contents, then hide them
// Cache elements that need to be reused
var tabContents = $(".tab_container, #side-img-container").children().hide(),
tabs = $("ul.tabs li");
// Show the first tab's content, and add in the active class
tabs.first().addClass("active");
tabContents.filter(':first-child').show();
// Attach click event handler
tabs.click(function() {
// Cache the clicked on tab element
var $this = $(this),
// Obtain the element index number
activeTab = $this.index() + 1;
// Only change tabs if the clicked tab isn't active
if (!$this.hasClass('active')) {
// Remove the 'active' class from the original anchor and add it to the current one
$this.addClass('active').siblings().removeClass('active');
// Hide all of the other tabs and fade in the active one
tabContents.siblings().hide().filter(':nth-child(' + activeTab + ')').fadeIn();
}
return false;
});
См. Простую демонстрацию этого здесь: http://jsfiddle.net/ND7nU/