homepage Welcome to WebmasterWorld Guest from 54.167.138.53
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
how to access particular elements of a cell of a row of a html table
Sayantandutta



 
Msg#: 4378720 posted 4:20 pm on Oct 24, 2011 (gmt 0)

Suppose i have a table wherein i have x rows. In each row there are y1 y2 y3 elements. How do I access each of them in Javascript.

 

birdbrain

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4378720 posted 6:25 pm on Oct 24, 2011 (gmt 0)

Hi there Sayantandutta,

here is an example for you to try...


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="language" content="english">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">

<title></title>

<style type="text/css">
#mytable {
border:2px outset #999;
margin:auto;
}
#mytable td {
padding:5px;
border:1px inset #999;
}
</style>

<script type="text/javascript">
function init(){
var tr=document.getElementById('mytable').rows;
for(var c=0;c<tr.length;c++) {
for(var k=0;k<tr[c].cells.length;k++){
tr[c].cells[k].firstChild.nodeValue='row '+c+' cell '+k;
}
}
}
window.addEventListener?
window.addEventListener('load',init,false):
window.attachEvent('onload',init);
</script>

</head>
<body>

<table id="mytable"><tr>
<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
</tr><tr>
<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
</tr><tr>
<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
</tr></table>

</body>
</html>

birdbrain

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved