/    Sign up×
Community /Pin to ProfileBookmark

number list

Hello,
I have a script which I type in a data table .
What I want is to print the row number near each row but to also have a button that switch this option on and off.
is this possible with javascript?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@yaronauthorSep 16.2003 — if the option is off and teh button is clicked then my table will like this

1. data1

2. data2

3. data3

and if the option is on and the button is clicked then my table will like it looks now.

data1

data2

data3
Copy linkTweet thisAlerts:
@pyroSep 16.2003 — Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
.num {
width: 15px;
}
.altnum {
display:none;
}
</style>

<script type="text/javascript">
function setNums(action) {
table = document.getElementById("mytable");
td = table.getElementsByTagName("td");
for (i=0; i<td.length; i++) {
if (action == "hide") {
if (td[i].className == "num") {
td[i].className = "altnum";
}
}
else {
if (td[i].className == "altnum") {
td[i].className = "num";
}
}
}
}
</script>

</head>

<body>
<p><a href="javascript:void(0);" onclick="setNums('hide'); return false;">hide</a> | <a href="javascript:void(0);" onclick="setNums('show'); return false;">show</a></p>
<table id="mytable" style="border: 1px solid;">
<tr>
<td class="num">1</td>
<td>One</td>
</tr>
<tr>
<td class="num">2</td>
<td>Two</td>
</tr>
<tr>
<td class="num">3</td>
<td>Three</td>
</tr>
</table>
</body>
</html>
×

Success!

Help @yaron 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.17,
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,
)...