First, create a simple horizontal menu HTML structure. This is HTML5 structure, but feel free to use the old div/ul combination if your project doesn't use HTML5. Make sure you give each an easy to remember ID so that jQuery can identify each one, and link each to a hash tag (#).
Below that, create four paragraph tags that you can use as your content. In a production use site, we might want to use AJAX calls to grab the information instead. For the sake of this post however, the paragraphs will be in the structure. To make this easy, we'll give each paragraph tag an ID that starts with its corresponding menu item ID, and adds another letter or phrase at the end of it ("p" in this example).
Next we'll add our CSS. This is all style so feel free to play around with it. The movement is handled by jQuery and the HTML IDs, so just use the CSS to make it look good and easy to navigate. I would recommend at least a hover effect so the user knows what to expect. Also consider adding an active class for the tab currently in use.
Now in your Javascript file, add these lines of code.
When the page first loads, hide the paragraphs, but show the one corresponding to the first of your menu items. It may be a better choice not to put this inside $(document).ready()
because currently the page is loading all of the paragraphs in to view, then removing them once the javascript is read, but again for the sake of this example it's going to stay there.
Now add your click function. Don't forget too add a preventDefault() in order to keep the link in the menu from trying to open up a new link. You'll then want to hide the current paragraph shown, then slide down the one that was selected.
There you go, a decent starting place for a little tabbed box that can save you space on your website. Try out the CodePen example for yourself below to see how it works.