/    Sign up×
Community /Pin to ProfileBookmark

Hide/Show Rows In a Table…

I’m trying to make a table that will hide multiple rows in single js functions… now I put together a way to do it, but it requires multiple id declarations in the functions, is there any way to do it with classes instead of IDs, so that I can have a blanket class that I can use?

See:

[CODE] <!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Javascript hide table row</title>
</head>
<body>
<script type=”text/javascript”>
function display2B(){
var row = document.getElementById(“T2B-1″);if (row.style.display == ”) row.style.display = ‘none’;else row.style.display = ”;
var row = document.getElementById(“T2B-2″);if (row.style.display == ”) row.style.display = ‘none’;else row.style.display = ”;
}

function display1B(){
var row = document.getElementById(“T1B-1″);if (row.style.display == ”) row.style.display = ‘none’;else row.style.display = ”;
var row = document.getElementById(“T1B-2″);if (row.style.display == ”) row.style.display = ‘none’;else row.style.display = ”;

}

</script>

<p><a href=”javascript: display1B();”>Show / Hide First Base</a></p>
<p><a href=”javascript: display2B();”>Show / Hide Second Base</a></p>
<table width=”300″ border=”1″>
<tr class=”topRow”><th>Name</th><th>Position</th><th>Average</th></tr>
<tr id=”T2B-1″><td>Joe Secondbase</td><td>2B</td><td>.259</td></tr>
<tr id=”T2B-2″><td>Bill Secondbase</td><td>2B</td><td>.292 </td></tr>
<tr id=”T1B-1″><td>Ralph Firstbase</td><td>1B</td><td>.223 </td></tr>
<tr id=”T1B-2″><td>Mickey Firstbase</td><td>1B</td><td>.249 </td></tr>

</table>
</body>
</html>[/CODE]

to post a comment
JavaScript

1 Comments(s)

×

Success!

Help @matstars spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...