Ok, as of now you’re relying on adding a hash to the current page, setting divs to inline-block as opposed to block ( the native display method ), and inline JS which could be vastly improved.
Do this right and it’ll work out fine, the first step is to remove all that inline JS and set the ID to the corresponding info div that will popup.
Step #1: Remove inline JS and add IDs to the table rows in table#data_table, as well as remove the “date” class from the table cells ( and I know you’re relying on them for CSS but thats ok we’ll modify that as well ).
Example:
<tr onclick="window.location='#'; document.getElementById('data_table').style.display='none'; document.getElementById('data_heading_left').style.display='none'; document.getElementById('data_details').style.display='inline-block'; document.getElementById('details1953').style.display='inline-block'; " class="data">
<td class="data ismore">+</td>
<td class="data">February 26, 2006</td>
<td class="data">201</td>
<td class="data">6.3</td>
<td class="data">32.1</td>
</tr>
Becomes
<tr id="row-details1953" class="data">
<td class="ismore">+</td>
<td>February 26, 2006</td>
<td>201</td>
<td>6.3</td>
<td>32.1</td>
</tr>
Step #2: Modify the two css rules you have for .data, .data_do as such:
.data_do, tr.data, tr.data td {
border-left:1px solid #CCCCCC;
cursor:pointer;
font-size:11px;
padding:5px 0 5px 7px;
}
Also, we’ll need to modify .heading_option because we’re changing your inline-blocks to regular block ( IE doesnt support inline-block on anything but native inline elements ):
.heading_option {
margin:-15px 0 0;
}
Step #3: Place this JS right before the </body> end tag:
(function() {
var toggle = function( el, str ) {
if (!str ) {
el.style.display = ( el.style.display === '' ) ? 'none' : '';
} else {
el.style.display = str;
}
},
getId = function( id ) { return document.getElementById(id) },
table = getId('data_table'),
backTo = getId('data_details').getElementsByTagName('a')[0],
currentlyOpen,
getElementsByClassName =
document.getElementsByClassName ? function (class_name, scope) {
return (scope || document).getElementsByClassName(class_name);
}
: document.querySelectorAll ? function (class_name, scope) {
return (scope || document).querySelectorAll("." + class_name);
}
: document.evaluate ? function (class_name, scope) {
var n,
r = [],
x = document.evaluate("descendant::*[contains(concat(' ', @class, ' '), ' " + class_name + " ')]",
scope || document, null, 5, null);
while (n = x.iterateNext()) {
r.push(n);
}
return r;
}
: function (class_name, scope) {
scope = scope || document;
var nL = scope.all || scope.getElementsByTagName("*"),
r = [];
for (var i = 0, n; n = nL[i]; ++i) {
if (n.className && (' ' + n.className + ' ').indexOf(' ' + class_name + ' ') != -1) {
r.push(n);
}
}
return r;
};
if (!table || !backTo) { return; }
var rows = getElementsByClassName('data', table);
if (!rows.length){return;}
for ( var i = 0, l = rows.length, row; i < l; ++i ) {
row = rows[i];
row.onclick = function() {
var corresponding = this.id.slice(4);
currentlyOpen = getId(corresponding);
if (!currentlyOpen ) { return false; }
toggle( getId('data_table') );
toggle( getId('data_heading_left') );
toggle( getId('data_details'), 'block' );
toggle( currentlyOpen, 'block' );
return false;
}
}
backTo.onclick = function() {
toggle( getId('data_table') );
toggle( getId('data_details') );
toggle( getId('data_heading_left') );
toggle( currentlyOpen );
return false;
}
})();
Note #1 - I did use a getElementsByClass fn that’s more optimized for newer browsers
Note #2 - For table rows which did not have a corresponding details div ( the ones without plus signs ) clicking does nothing, while currently your page hides the initial table and attempts to show a div. I’m guessing this is because your code is in a php loop, this won’t be a problem as my JS does the logic to check if theres a corresponding div.
Here’s my local page on a server, so you can see the changes for yourself:
http://inimino.org/~amthx/table.html
Let me know if you have any issues. I only tested the JS if it’s added to this page alone, though it shouldn’t break if its added globally.