View Full Version : Help with coding

05-09-2009, 12:35 AM
Hello, first time posting on forum, hope you guys can help me with this problem I have.

I'm basically trying to get the value from a div tag and compare it to something else, like "05:10:50" and, if they are the same I want it to run something else.
The value in the div tag is dynamic and always changes. That's why I want it to run another piece of code once it has matched "05:10:50".

Code for getting the value.


I am completely stumpped as to how to do this but I know it'll involve "if...else" and "while".


05-09-2009, 01:11 AM
It's important to identify that the first child is the text. For more take a look at


And especially the [2a] Getting the Text Value of an Element part

05-09-2009, 03:43 AM
Thanks for that bit of info.

Ok so I have this now, which works perfectly, but I now need it automated.

counter = document.getElementById("divid").firstChild.nodeValue;
target = "00:50:10";
if (counter == target)

I was wondering how you would go about looping through all this (as my target is dynamic) but also having a time interval between each loop because it will crash.

Philip M
05-09-2009, 08:12 AM
<body onload = "checkTarget()">

<script type = "text/javascript">

target = "05:50:10";
function checkTarget() {
counter = document.getElementById("divid").firstChild.nodeValue;
if (counter == target) {
doSomethingElse(); // call another function
return false;
window.setTimeOut("checkTarget()", 2000); // check every two seconds


Do please read the posting guidelines regarding thread titles. The thread title is supposed to help people who have a similar problem in future. Yours is useless for this purpose. You can edit it to someting more meaningful.