Basic Tabs in Javascript
Submitted by Yorkiebar on Thursday, April 24, 2014 - 11:33.
Introduction:
This tutorial is on how to create simple, small tabs in Javascript.
When I say 'small tabs', I mean that this shouldn't be used for tabs holding large amounts of content.
HTML:
First we want to create a text area in which we are going to be holding the tab content...
Then we want a few buttons to act as options to change the current tabs. We simply parse the tab number to the function 'update'...
Javascript:
Now we want to create a couple of Javascript variables. First we want an integer named 'indexid' to hold the current tab index/number. And we also want an array of strings which contain the tabs content, we'll name this 'values'...
Finally we want to make our 'update' function. We want to accept one parameter which is the new tab id. We then set the variable holding the current tab id ('indexid') to the new 'id' parsed value, and update the text of our textarea with the id of 'area' with the new tabs content - we simply pull this from our 'values' string array at the element index of the parsed 'id' value to the function...
Add new comment
- 31 views