/    Sign up×
Community /Pin to ProfileBookmark

Retrieve a value from Table row?

Is there a way to retrieve a value from first TD tag?

Here is an example:

<html>
<script language=”JavaScript”>
function go() {
var m = document.getElementsByTagName(“TD”);
alert(m.length);
}
</script>
<body>
<table onMouseOver=”go();”>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
</tr>
</table>
</body>
</html>

Alert displays 3. I am not able to retrieve value from first element.

I tried document.getElementsByTagName(“TD”).item(0).value;

Or a different approach? Thanks.

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@SixteaseNov 10.2007 — Change the [FONT="Courier New"]alert(m.length);[/FONT] line for

[FONT="Courier New"]alert(m[0].innerHTML);[/FONT]

Since m is an array of the <td>'s, you simply index it to get the first of them. The content is accessible through the (non-W3-specified but working in most browsers) innerHTML attribute.

I would recommend you dwelwing into the JavaScript and DOM tutorials on w3schools.com
×

Success!

Help @codingisfun 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.8,
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,
)...