Reputation: 431
I want to run a function when var roll_time = $('#banner')[0].childNodes[0].textContent;
is == "Rolling in 25.00..."
i have tried to do so with this code, but i do not get an output. The text in the <span>
is changing every 10 millisecond.
setInterval(test, 10)
function test(roll_time) {
var roll_time = $('#banner')[0].childNodes[0].textContent;
if (roll_time == "Rolling in 25.20...") {
console.log(success) }
}
<span id="banner">Rolling in 25.20...</span>
Upvotes: 0
Views: 65
Reputation: 3130
Thats because you are trying to access the roll_time which populate the value during the load.
$('#banner')[0].childNodes[0].textContent is a string, not a reference and hence if you need to access the string at a later point of time, you need to explicitly read the value from the DOM.
setInterval(test, 10)
function test() {
var roll_time = $('#banner')[0].childNodes[0].textContent;
if (roll_time == "Rolling in 25.20...") {
console.log("success");
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span id="banner">Rolling in 25.20...</span>
Upvotes: 2