| | |
Spry tabs
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
0
#2 16 Days Ago
Hey.
Creating a simple "tabs" system using AJAX is easy enough. Especially if you use jQuery, or something equivalent.
You could just put the contents of all your tabs in separate HTML files, and use AJAX to load them into a <div> in your HTML.
For example, assuming the following structure:
You could simply do:
And to make it pretty: (And I use that term very lightly)
Hope that helps.
Creating a simple "tabs" system using AJAX is easy enough. Especially if you use jQuery, or something equivalent.
You could just put the contents of all your tabs in separate HTML files, and use AJAX to load them into a <div> in your HTML.
For example, assuming the following structure:
text Syntax (Toggle Plain Text)
root/ index.html tabs.js styles.css tabs/ tab1.html tab2.html tab3.html
You could simply do:
html Syntax (Toggle Plain Text)
<!DOCTYPE html> <html> <head> <title>AJAX Tabs Example</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="Stylesheet" type="text/css" href="styles.css"> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="tabs.js"></script> </head> <body> <div id="TabContainer"> <ul id="TabMenu"> <li onclick="SwitchTab('tab1');">Tab 1</li> <li onclick="SwitchTab('tab2');">Tab 2</li> <li onclick="SwitchTab('tab3');">Tab 3</li> </ul> <div id="TabContents">Loading...</div> </div> </body> </html>
javascript Syntax (Toggle Plain Text)
/** * File: tabs.js */ $(document).ready(function() { // When the page loads, load the first tab. SwitchTab('tab1'); }); function SwitchTab(tabName) { // Put a Loading message in the TabContents div $('#TabContents').html('Loading...'); // Create the URL to the tab's HTML page. var url = 'tabs/' + tabName + ".html"; // Fire of an AJAX query to get the tab HTML $.get(url, null, function(data){ // Change the contents of the TabContents div to the returned HTML $('#TabContents').html(data); }, 'html'); }
And to make it pretty: (And I use that term very lightly)
css Syntax (Toggle Plain Text)
/** * File: styles.css */ root { display: block; font-size: 1.5em; font-family: Verdana, Arial, Sans; } #TabContainer { width: 550px; border: solid 1px #000000; margin: 15px auto; } #TabMenu { display: block; height: 25px; margin: 0; padding: 0; background-color: #bfbfbf; border-bottom: solid 1px #000000; } #TabMenu li { display: block; float: left; min-width: 50px; height: 25px; padding: 0 3px; background-color: #dfdfdf; border-right: solid 1px #333333; line-height: 25px; text-decoration: underline; cursor: pointer; } #TabMenu li:hover { background-color: #efefef; } #TabContents { clear: both; padding: 5px; }
Please do not ask for help in a PM. Use the forums.
And use [code] tags!
And use [code] tags!
![]() |
Similar Threads
- Vertical Spry Menu Bar Align Issues in Dreamweaver CS3 (HTML and CSS)
- Spry makes me cry :'( (JavaScript / DHTML / AJAX)
- Missing TaskManager tabs can someone help? (Windows NT / 2000 / XP)
- Tabs causing errors (PHP)
- Hi (Viruses, Spyware and other Nasties)
- Menu bars and tabs in VB.NET (VB.NET)
- Missing Internet Options Tabs (Web Browsers)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: dhtml, element calling function that destroys element causes page reload, why?
- Next Thread: problem with pictures
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array beta box browser captchaformproblem cart child class close codes column css date debugger decimal dependent design disablefirebug dom download editor element embed engine enter error events explorer ext file firefox focus form forms frameworks getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe index java javascript javascripthelp2020 jquery jsf jsp jump libcurl listbox maps masterpage math media menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php player position post problem programming prototype redirect safari scale scriptlets scroll search security select software toggle unicode variables w3c web window windowofwords \n





