Solved

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

Posted on 2014-07-25
1
133 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now