Reputation:
im using the code
setInterval(function() {
if (document.querySelector("#shrimpCook01").style.top > "400px") {
alert("789")
}
}, 200);
to check where shrimpcook01 is, but im receiving an alert message even though the div's top value is less than 400px.
Upvotes: 1
Views: 110
Reputation: 1640
You can transform your string values easily.
setInterval(function() {
const height = document.querySelector("#shrimpCook01").style.top.split('px')[0];
if (Number(height) > 400) {
alert("789")
}
}, 200);
Upvotes: 1
Reputation: 43265
It would be doing lexicographical comparison of strings. Use parseInt to convert the value to number, and compare it against 400 number, not "400px" string.
Upvotes: 0