Ooops! I really shouldn't leave things half-baked like that.
If the link in question doesn't do anything without javascript, it is
a wise idea to have it written to the page using js as well.
We don't want any orphan UI elements, do we ;) 

And I even tested this one :]

//----let the code begin----

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
<head>
  <title>Hide Content Test</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function hideStuff() {
   var tr = document.getElementsByTagName('tr');
   for(var i=0; i<tr.length; i++ ) {
       if(tr[i].className == 'hide') {
            tr[i].style.display = 'none';
       }
   }
   return false;
}

function addHideLink() {
    var link = document.createElement('a');
    link.setAttribute('onclick', 'hideStuff()' );
    link.setAttribute('href', '#');
    link.appendChild(document.createTextNode('Hide Content'));
    var parent = document.getElementById('hold');
    parent.appendChild(link);
}

window.onload = addHideLink;
</script>
</head>

<body>
<div id="hold"></div>
<table>
<tbody>
<tr>
<td>foo</td><td>bar</td>
</tr>
<tr>
<td>foo</td><td>bar</td>
</tr>
<tr class="hide">
<td>This one's gonna go</td><td>:)</td>
</tr>
<tr>
<td>foo</td><td>bar</td>
</tr>
<tr class="hide">
<td>..and</td><td>this one</td>
</tr>
</tbody>
</table>
</body>
</html>


This is a pretty rough example with poorly written scripts (ie: the
class names, id's and function to be attached to the created element
should be passed as var's), but it works and it gives you something
you can improve on.

Cheers,
Andrew.
--------------------------------
http://leftjustified.net/
******************************************************
The discussion list for  http://webstandardsgroup.org/

 See http://webstandardsgroup.org/mail/guidelines.cfm
 for some hints on posting to the list & getting help
******************************************************

Reply via email to