Advertise
  • Home
  • Menus
  • Blog
  • Contact

Cookies are currently necessary for this site to operate properly.

    Categories

    • Development (9)
    • Extras (3)
    • General (6)
    • Tutorials (6)

    Archives

    • April 2010 (3)
    • November 2009 (4)
    • October 2008 (1)
    • September 2008 (8)
    • August 2008 (1)
    • July 2008 (4)

    Most Recent Posts

    • 5 Free CSS Menu Builders
    • CSS Menu Builder Video Tutorial
    • Site quite unstable – FIXED
    • Centering a menu using either CSS, MooTools, jQuery or just plain JavaScript
    • 50.000 downloads since launch

    My Writing

    If you don't like dry sarcastic humour, please don't read any more of this blog, because I have a tendency to use it without thinking about it.

    This blog will mainly be used as a development log, since I am not a big blogger and don't really have anything worth saying, though I might write a few tutorials and suggested usage articles along the way.

    Oh by the way, in this blog, which is currently the only blog I am active on, I go by the original name of admin. I will not be commenting that much, but when I do, this is the name you will see.

jQuery tabbed content example

yes you guessed it, this also uses images from the horizontal css menu builder, actually it uses the exact same images as the earlier example that used MooTools as the javascript library. That’s the definition of laziness for you!

If you are using the MooTools version or read that post or have not had problems in browsers with that version or are never going to use these javascript tab menus, then there is really no point in reading the rest of this post. On the other hand, if you love reading about this stuff, please be my guest and read the rest of the post.

I did this version of my tabbed content script only because there was a comment on the previous version, saying that it did not work in IE7. It did work in my IE7, but for some reason, it did not work in some other IE7’s and after rewriting the MooTools version, it still did not work in that website when viewed by some IE7’s.

So, I thought it might be a good idea to try and provide an alternative to the MooTools version and for no particular reason, jQuery was the choice . I actually also considered using Dojo, but due to the lack of quality documentation, I changed my opinion, so if any of the few people reading this blog are firm in Dojo and have nothing better to do, you are more than welcome to add a comment with a link to your tab tutorial.

Well enough pre-talk, lets get to it.

I was supprised how short the code became, though I am sure it would also be possible to shorten the MooTools code. The jQuery version of the tabbed content script is only 13 lines of code, but it could be even shorter, if you moved the function code inside the document ready container. I chose not to do this, as I like having the functions, to get a better overview of the various sections of javascript code.

Here is the javascript code

$(document).ready(function(){
initTabs();
});

function initTabs() {
$('#tabMenu a').bind('click',function(e) {
e.preventDefault();
var thref = $(this).attr("href").replace(/#/, '');
$('#tabMenu a').removeClass('active');
$(this).addClass('active');
$('#tabContent div.content').removeClass('active');
$('#'+thref).addClass('active');
});
}

And to see what it actually does, here are the links to the examples.

jQuery tabs at the top of the container

jQuery tabs at the bottom of the container

Note
By the way, if you started out with the MooTools version, but now want to use the jQuery version, all you have to do is change the javascript, since the rest is the same.

And another note
This version will not break if javascript is disabled, though you would have to create the pages with the tabs open, in accordance to the URL you put in the href attribute. An example could be using a server-side rewrite and then capturing the last part of the URL and with this information activate the tab, by adding “active” the the class of the DIV element.

Third and final note
Though I wrote the tabbed content script for two different javascript libraries, I do not expect to do this in the future. I usually use MooTools and am quite happy doing so. It takes time to learn how to use a new library and then you might mix them and break the code you are trying to write, or at least I might do this. Furthermore I believe it is a good idea to learn one and learn it well, than learning them all, but badly. This does not mean that MooTools is the best in the world, but I guess it is the one I have come to like.

September 28th, 2008
Comments (1)
Filed under: Extras, Tutorials

One Response to “jQuery tabbed content example”

  • Comments
  • Pings
  1. 7 jQuery Tabbed Interface / Tabbed Structure Menu Tutorial | Theme Heven says:
    June 10, 2009 at 07:52

    [...] 4. Cssmenubuilder [...]

Info

  • Information for advertisers
  • Terms of Service
  • Privacy
  • License

About

This is my small contribution to the world of web designers, programmers, web enthusiasts and others who have helped me or need help or just don't want to take the time to learn how to do this in photoshop etc.

These menus are licensed under the MIT license

Clicky Web Analytics
V:II | XHTML | CSS | Bluehost | GA & Clicky
2008 - 2010 | This is a [Super Simple Services] site.