A
alex.pedwysocki
I am trying to change some elements from one class to another using
javascript. I would have expected the browser to apply the styles for
those classes, but they don't seem to bother and I would be really
interested to know what I could do about it.
Manually changing each property would work, but I don't want to if
this can be made to work reasonably.
Here is some code:
Some js:
function switchTab( i ) {
//terminology: tab is the bit at the top
//tab contents is the stuff that shows up underneath
//grab the new open tab (the selected close tab)
var nt = document.getElementById("t" + i);
//grab the new query tab contents
var ntc = document.getElementById("qt" + i);
for ( var x = 1; x < 11; x++ ) {
//set both the query tabs (tab contents) and the tabs themselves to
closed mode
//setting to closed mode involves resetting all of the parameters
var tab = document.getElementById("t" + x).setAttribute("class",
"ctab");
document.getElementById("qt" + x).style.display = 'none';
}
//set the new tab contents to being visible.
ntc.style.display='block';
//set the new open tab to open mode;
nt.setAttribute("class", "otab");
}
some css:
td.otab {
text-align:center;
background-color: AliceBlue;
padding: 0px 20px;
border-color: black;
border-top: 2px solid;
border-right: 2px solid;
border-left: 2px solid;
}
td.ctab {
text-align:center;
border-color: black;
border: 1px solid;
border-bottom: 2px solid;
}
table.tabs {
position: relative; /* This positioning is a hack to get the borders
to align right. */
top: 1px; /* It is only necessary for firefox but doesn't
upset IE */
width:938px;
border-collapse: collapse;
}
And selected bits of html look like this.
<table class="tabs">
<tr>
<td id="t1" class="otab" name="t" onclick="switchTab(1);">Query 1</
td>
<td id="t2" class="ctab" name="t" onclick="switchTab(2);">Query 2</
td>
<td id="t3" class="ctab" name="t" onclick="switchTab(3);">Query 3</
td>
<td id="t4" class="ctab" name="t" onclick="switchTab(4);">Query 4</
td>
<td id="t5" class="ctab" name="t" onclick="switchTab(5);">Query 5</
td>
<td id="t6" class="ctab" name="t" onclick="switchTab(6);">Query 6</
td>
<td id="t7" class="ctab" name="t" onclick="switchTab(7);">Query 7</
td>
<td id="t8" class="ctab" name="t" onclick="switchTab(8);">Query 8</
td>
<td id="t9" class="ctab" name="t" onclick="switchTab(9);">Query 9</
td>
<td id="t10" class="ctab" name="t" onclick="switchTab(10);">Query 10</
td>
</tr>
</table>
....
And this is what the tab contents div declarations look like:
<div name="qt" class="queryTab" id="qt1" style='display:block;' >...</
div>
<div name="qt" class="queryTab" id="qt2" style='display:none;' >...</
div>
etcetera.
The tab contents appear as expected. As for the tab tops
themselves . . . In IE, they don't change at all. In firefox, SOME
PARTS of the formatting defined by the stylesheet change depending on
which button was clicked. Since they should all be roughly the same,
that is sort of terrifying.
Thank you very kindly for your time.
javascript. I would have expected the browser to apply the styles for
those classes, but they don't seem to bother and I would be really
interested to know what I could do about it.
Manually changing each property would work, but I don't want to if
this can be made to work reasonably.
Here is some code:
Some js:
function switchTab( i ) {
//terminology: tab is the bit at the top
//tab contents is the stuff that shows up underneath
//grab the new open tab (the selected close tab)
var nt = document.getElementById("t" + i);
//grab the new query tab contents
var ntc = document.getElementById("qt" + i);
for ( var x = 1; x < 11; x++ ) {
//set both the query tabs (tab contents) and the tabs themselves to
closed mode
//setting to closed mode involves resetting all of the parameters
var tab = document.getElementById("t" + x).setAttribute("class",
"ctab");
document.getElementById("qt" + x).style.display = 'none';
}
//set the new tab contents to being visible.
ntc.style.display='block';
//set the new open tab to open mode;
nt.setAttribute("class", "otab");
}
some css:
td.otab {
text-align:center;
background-color: AliceBlue;
padding: 0px 20px;
border-color: black;
border-top: 2px solid;
border-right: 2px solid;
border-left: 2px solid;
}
td.ctab {
text-align:center;
border-color: black;
border: 1px solid;
border-bottom: 2px solid;
}
table.tabs {
position: relative; /* This positioning is a hack to get the borders
to align right. */
top: 1px; /* It is only necessary for firefox but doesn't
upset IE */
width:938px;
border-collapse: collapse;
}
And selected bits of html look like this.
<table class="tabs">
<tr>
<td id="t1" class="otab" name="t" onclick="switchTab(1);">Query 1</
td>
<td id="t2" class="ctab" name="t" onclick="switchTab(2);">Query 2</
td>
<td id="t3" class="ctab" name="t" onclick="switchTab(3);">Query 3</
td>
<td id="t4" class="ctab" name="t" onclick="switchTab(4);">Query 4</
td>
<td id="t5" class="ctab" name="t" onclick="switchTab(5);">Query 5</
td>
<td id="t6" class="ctab" name="t" onclick="switchTab(6);">Query 6</
td>
<td id="t7" class="ctab" name="t" onclick="switchTab(7);">Query 7</
td>
<td id="t8" class="ctab" name="t" onclick="switchTab(8);">Query 8</
td>
<td id="t9" class="ctab" name="t" onclick="switchTab(9);">Query 9</
td>
<td id="t10" class="ctab" name="t" onclick="switchTab(10);">Query 10</
td>
</tr>
</table>
....
And this is what the tab contents div declarations look like:
<div name="qt" class="queryTab" id="qt1" style='display:block;' >...</
div>
<div name="qt" class="queryTab" id="qt2" style='display:none;' >...</
div>
etcetera.
The tab contents appear as expected. As for the tab tops
themselves . . . In IE, they don't change at all. In firefox, SOME
PARTS of the formatting defined by the stylesheet change depending on
which button was clicked. Since they should all be roughly the same,
that is sort of terrifying.
Thank you very kindly for your time.