Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

how to get a control in a data cell using java script

Posted on 2014-07-25
1
136 Views
Last Modified: 2014-07-27
Suppose my Java Script is iterating through a table row and cell
at a time. Meaning accessing the contents of each <td> cell.

I know that I can access the contents of the cell using innerhtml. That works
good when there is data in the cell.

However what if there is a control in the cell. Like a label control for example.
How would I access that control, so that I can get the id of the control?

You see when the java script is iterating through each cell, it has no idea if the
data in each cell is a control or just data, like "Hello World".



<table>
<tr>
<td>Hello World</td>
</tr>

<tr id="outter">
<td id="inner">
<Label id="Label1" Text="Label Control" runat="server"/>
</td>
</tr>

</table>
0
Comment
Question by:brgdotnet
1 Comment
 
LVL 63

Accepted Solution

by:
Zvonko earned 310 total points
ID: 40219769
What about this:
<htm>
<head>
<title>Zvonko &#42;</title>
</head>
<body>
<table>
<tr>
<td>Hello World</td>
</tr>
<tr id="outter">
<td id="inner">
<Label id="Label1" Text="Label Control" runat="server"/>
</td>
</tr>
</table>
<script>
var theTab = document.getElementsByTagName("table")[0];
var theCell = theTab.rows[1].cells[0];
var theLabels = theCell.getElementsByTagName("label");
alert(theLabels[0].id);
</script>
</body>
</html>

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question