accessing a range of rows in table

A

anagai

hi

I have a javascript function that will add a column of numbers in html
table. Is there a way to assign a ID to a group of table rows that so i
can easily access the rows through getelementbyid and childnode? I have
tried surrounding rows with a tbody tag and assing a id to that. I cant
access it through dom. Ive tried surrounding rows with a span tag, with
no success. For now i will just have to use the old tbl.rows method to
access the rows. This method is clusmy if you want to make a reusable
function for summing data and need to ignore all the extra rows such as
title and spacer rows.
 
J

Jonas Raoni

anagai escreveu:
For now i will just have to use the old tbl.rows method to
access the rows. This method is clusmy if you want to make a reusable
function for summing data and need to ignore all the extra rows such as
title and spacer rows.

I don't see anything wrong with the rows property...

Anyway, what you're trying to do is possible, have you ever seen those
"javascript css selectors"? You could make an extended version or just
make a function where you send an element list and a callback function
to filter those who matched your criteria... Maybe it's also possible
to achieve your goal with xpath (I didn't read about it yet)... But if
you can do it using simple js, why not? :)

There are certain circunstances where it isn't possible to make a 100%
reusable code, but if you can reuse 70% of it or at least the most
annoying part, it's already great :)

It's just my opinion =]
 
G

Gérard Talbot

anagai wrote :
hi

I have a javascript function that will add a column of numbers in html
table. Is there a way to assign a ID to a group of table rows that so i
can easily access the rows through getelementbyid and childnode? I have
tried surrounding rows with a tbody tag and assing a id to that. I cant
access it through dom.

tBodies (HTML collection)
http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-63206416

No need to assign an id.


Ive tried surrounding rows with a span tag, with
no success.

That's invalid markup code to begin with.


For now i will just have to use the old tbl.rows method to
access the rows. This method is clusmy if you want to make a reusable
function for summing data and need to ignore all the extra rows such as
title

title? You mean column headers semantically identified as <th>?


and spacer rows.

Are you actually using some sort of code like
<tr><td><img src="spacer.gif" width="..." height="..."
alt=""></td><td><img src="spacer.gif" width="..." height="..."
alt=""></td></tr>

Why not use cellspacing's table attribute?

If you have added a column of numbers and want to access that column of
table cells, then why not just do that?
You have not posted an url so it's difficult to know for sure what your
code might be needing.

Gérard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top