How do i go about this?
i tried doing if(document.getElementById("cart-remove")[0])
but that gives me the error: ERROR: Execution of script 'New Userscript' failed! Cannot read property '0' of null
Thanks Alot.
How do i go about this?
i tried doing if(document.getElementById("cart-remove")[0])
but that gives me the error: ERROR: Execution of script 'New Userscript' failed! Cannot read property '0' of null
Thanks Alot.
Use this code:
if(document.getElementById("cart-remove"))
{
// some code here
}
you can try
if (document.getElementById("cart-remove") === null) {
.....
}
if(document.getElementById("cart-remove")){}
if document.getElementById("cart-remove") is null, then document.getElementById("cart-remove")[0] will give you an error.
You can also do:
if(document.getElementById("cart-remove") && document.getElementById("cart-remove")[0]){}
Since document.getElementById("cart-remove")[0] will give you an error if document.getElementById("cart-remove") is null, you first check document.getElementById("cart-remove") and then document.getElementById("cart-remove")[0].
null is one of the falsy values in Javascript
if(document.getElementById("car-remove"))
Use equality ===
check inside if condition
if (document.getElementById('x') === null) {
console.log('It is null')
}
<div id="test">Test</div>