I'm trying to execute a function in js through an html style property, but cannot get it to work.
I have a js function (jscode in example), which works with a shortcut. I want to circumvent this, by trying to get the code to execute itself when an html class on the webpage has 600px (the loading bar has 600px, when it finishes, the code should run with a delay of 1ms)
function test() {
setTimeout(function () { jscode(); }, 1);
}
var htmltest = document.getElementsByClassName("loadingbar");
var htmlteststyle = htmltest[0].style;
if (htmlteststyle.width == '600px') {
console.log("success");
test();
}
It's not working at all, the console message does not appear and the js file executes itself only until this snippet comes up.
I'm just starting to play around with js and html and don't know where I went wrong, maybe it's a completely wrong approach?
any advice appreciated.