0

I am trying to access the <td>'s in following:

<table class="datadisplaytable" summary="This table lists the scheduled meeting times and assigned instructors for this class..">
<caption class="captiontext">Scheduled Meeting Times</caption>
<tbody><tr>
<th class="ddheader" scope="col">Time</th>
<th class="ddheader" scope="col">Days</th>
<th class="ddheader" scope="col">Where</th>
<th class="ddheader" scope="col">Date Range</th>
<th class="ddheader" scope="col">Schedule Type</th>
<th class="ddheader" scope="col">Instructors</th>
</tr>
<tr>
<td class="dddefault">8:35 AM - 9:55 AM</td>
<td class="dddefault">TR</td>
<td class="dddefault">Trottier Building 0100</td>
<td class="dddefault">Jan 05, 2015 - Apr 13, 2015</td>
<td class="dddefault">Lecture</td>
<td class="dddefault">Harry Leib </td>
</tr>
</tbody></table>

I have a bunch of these tables in a HTML collection called var data_tables and I can successfully access the caption with data_tables[0].childNodes[0].innerText(i.e. for the first table in the collection). However when I try to access the <td>'s (for example the text "8:35 AM - 9:55 AM") with data_tables[0].childNodes[1].childNodes[1].childNodes[0].innerText I get "undefined" when using Chrome. What am I missing? Is the <td> not three layers of nodes deep from the <table>?

1 Answer 1

1

You may be getting a text node instead of the td element.

Don't use .childNodes with tables. Instead use the .tBodies, .rows and .cells collections.

data_tables[0].tBodies[0].rows[1].cells[0].innerText

Also, I'd use .textContent instead of .innerText so that you're using the standard property.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that worked. Where can I find documentation on the standard properties to be used?
You're welcome. Mozilla has lots of JS docs: MDN JavaScript

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.