crobar
07-14-2008, 03:04 PM
i attempted to make tabs in JavaScript and it works in fire fox & safari, but not IE...
the basic function works (switching content) but the tabs don't reset just change on click... Example (http://www.staticair.com/EX/tabs.html)
<script type="text/javascript">
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
//-------
function collapseAll(objs) {
var i;
for (i=0;i<objs.length;i++ ) {
objs[i].style.display = 'none';
}
}
//-------
function switchTab(obj) {
//------- list all tab content div ids in collapseAll.
collapseAll($('one','two','three','four','five'));
var el = document.getElementById(obj);
if ( el.style.display != "none" ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
//-------
function changer(obj,DivID) {
switchTab(DivID);
var lnks = document.getElementById("tabs").getElementsByTagName("a");
var lnkamnt = lnks.length+1;
for (var i = 0; i <= lnkamnt; i++) {
if (lnks[i].getAttribute('class') == "active") {
lnks[i].className = "inactive";
}
obj.className = "active";
}
}
//-------
function pageLoad() {
//------- collapseAll if you dont want any tabs open.
//collapseAll($('one','two','three','four','five'));
//------- set switch tab to your inital tab.(also set this tab class to active)
switchTab('one')
}
</script>
i don't write JavaScript too often so my script could be a complete mess and i wouldn't know.
I'm not sure what to do here any help here would be greatly appreciated.
Thanks
the basic function works (switching content) but the tabs don't reset just change on click... Example (http://www.staticair.com/EX/tabs.html)
<script type="text/javascript">
function $() {
var elements = new Array();
for (var i = 0; i < arguments.length; i++) {
var element = arguments[i];
if (typeof element == 'string')
element = document.getElementById(element);
if (arguments.length == 1)
return element;
elements.push(element);
}
return elements;
}
//-------
function collapseAll(objs) {
var i;
for (i=0;i<objs.length;i++ ) {
objs[i].style.display = 'none';
}
}
//-------
function switchTab(obj) {
//------- list all tab content div ids in collapseAll.
collapseAll($('one','two','three','four','five'));
var el = document.getElementById(obj);
if ( el.style.display != "none" ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}
//-------
function changer(obj,DivID) {
switchTab(DivID);
var lnks = document.getElementById("tabs").getElementsByTagName("a");
var lnkamnt = lnks.length+1;
for (var i = 0; i <= lnkamnt; i++) {
if (lnks[i].getAttribute('class') == "active") {
lnks[i].className = "inactive";
}
obj.className = "active";
}
}
//-------
function pageLoad() {
//------- collapseAll if you dont want any tabs open.
//collapseAll($('one','two','three','four','five'));
//------- set switch tab to your inital tab.(also set this tab class to active)
switchTab('one')
}
</script>
i don't write JavaScript too often so my script could be a complete mess and i wouldn't know.
I'm not sure what to do here any help here would be greatly appreciated.
Thanks