0
I have the following code, but the var ob
this coming null.
<head>
<script>
function pisca(item) {
var ob = document.getElementById(item);
if (ob.style.color=="red"){
ob.style.color="black";
}else{
ob.style.color="red";
}
}
</script>
</head>
<body>
<div id="piscar" style="color:#F00">
Texto piscando
</div>
<script>
t = setInterval("pisca('piscar')",500);
</script>
</body>
Good morning. You checked this on the console, which is coming null?
– Sam
"var ob this coming null." It wouldn’t be before
undefined
? In what situations is this happening ? Is there any way to show it to us ? Where is this null ?– Isac
It is worth remembering that the
var ob
has value only within the functionpisca
. If you want it to have global scope, you’d have to do it outside of functionvar ob;
and within the function without thevar
, onlyob = document.getElementById(item);
.– Sam
Thanks for the feedback, worked out just that!!
– Jandandan