Reputation: 25
The timer goes from 40 to 0 and the script should wait till there are just 100 miliseconds and press a button.
How can I get that number so it will be x = 14.22 *1000-100?
I know I need to delete te letters but how ?
Plese just javacript, no jquery!
var evt = document.createEvent("MouseEvents");
var run = document.getElementByClassName("button1");
setInterval(function() {
var time = document.getElementByClassName("Timer h4").innerHTML;
var x = time * 1000 - 100;
setTimeout(function() {
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
run.dispatchEvent(evt);
}, x);
}, 15000);
function x3a() {
document.getElementById("x3").innerHTML = 1;
}
<h4 class="Timer h4">Time expire in 14.22</h4> //how can I read this number 14.22 so I can use it?
<p id="x3"></p>
<button data-g="red" class="button1" onclick="x3a()">OK</button>
Upvotes: 2
Views: 54
Reputation: 63524
Pick up the h4
element, and use a regex to match against the numbers.
const el = document.querySelector('h4');
const txt = el.innerText.match(/\d+\.\d+/)[0];
console.log(txt);
<h4 class="Timer h4">Time expire in 14.22</h4>
Upvotes: 2