View Full Version : Help needed extracting title from td please

02-09-2010, 07:11 PM

I'm pretty new to Javascript, by about two weeks, I'm looking for help with a problem I have with the following....

<td title='text1;text2;text3'>text4</td></tr>

I'm trying to display text1-3 in a table cell on a rotation, I have this to count through the cells to get to the relevent one...

function rotateCell() {
var delayed = document.getElementsByTagName('td'); //.title.split(';');
for (var i=24;i<24;i++)

This should allow me to identify the location/cell 24 but can some one tell me how I then extract the tittle data and have them alternate within the cell?

I'm not allowed to edit the HTML.

Very gratefull for any help


02-09-2010, 07:31 PM
Well, document.getElementsByTagName returns a nodelist, which you can ennumerate using a for loop. I'd suggest something like this:

var delayed = document.getElementsByTagName('td'),
for (i = 0; i < delayed.length; i += 1) {
delayedTitle = delayed[i].getAttribute('title');
// delayedTitle now refers to the value of the title attribute for each td tag

Hope this helps,

02-09-2010, 07:39 PM

Thanks for posting, ill give that a try once I get home:)


Old Pedant
02-09-2010, 10:19 PM
I don't see how that helps him with the "rotation" part.

He still has to rotate through the individual chunks of the title, separated by semicolons. But he doesnt' say WHEN or on what basis he needs to do the rotation. Once a second? Each time the page is refreshed? When the user clicks on it???

More info, Sir Wild.

02-10-2010, 12:15 PM

OP, thanks for coming in on this, the function is on load regulated by interval3 below...

function ol(){
interval = setInterval(twicely,1000);
time = setTimeout('realTime()',500);
interval2 = setInterval(lingo,5000);
interval3 = setInterval(rotateCell,2000);

So at this point every two seconds is fine and I can adjust to suit depending on how the effect looks when it runs. This way works quite well with the other functions but I was wondering if it would be two seconds between rotation of the text or is it two seconds between each execution of rotateCell()?

The idea being that every two seconds it should rotate, text1, text2, text3. In the HTML, text 4 (the table data itself) is a duplication of text 1 so reverting back to the original table data is not needed. All the action for this occurs in td 24, so I need to identify that cell too, thats why I started and finished my original for loop at 24 instead of delayed.length, I'm assuming that would work however I'm still learning and could be waaaaay off.

The page itself doesn't consist of any user interaction so display only. I hope thats a bit clearer.

Jazzo, on your code the first line consists of (td),i,delayedTitle; sorry to appear a bit dumb but the comma's are confusing me, is that the the right syntax?

Thanks again guys, appreciate the help!


02-10-2010, 06:57 PM
All sorted, thanks to the posters for your help :)


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum