PDA

View Full Version : Need help targeting something with the DOM, please help?


sethwb
06-11-2009, 11:10 PM
Ok I need to target the first and last TR's here, but I can't figure out how to do it:




<div id="contentwrap">
<table>
<tbody>
<tr>
first tr
</tr>

<tr>
</tr>

<tr>
last tr
</tr>
</tbody>
</table>
</div>


This is what I've tried:

var landmark2 = document.getElementById('contentwrap');
var landmark3 = landmark2.firstChild;
var landmark4 = landmark3.firstChild;
// next two should be the first and last tr's
var firsttr = landmark4.firstChild;
var lasttr = landmark4.lastChild;


Any ideas?

Gjslick
06-17-2009, 12:24 AM
**pew pew!** Target that DOM! Lol, jp.


var contentWrap = document.getElementById( "contentWrap" );

var trElements = contentWrap.getElementsByTagName( "TR" );
var firstTR = trElements[ 0 ];
var lastTR = trElements[ trElements.length - 1 ];
Hope that helps.