+ 1

Vanilla version of this jQuery

Is there a vanilla javascript version of this jQuery: setInterval(function() { if ($('#cursor').css('visibility') === 'visible') { $('#cursor').css({ visibility: 'hidden' }) } else { $('#cursor').css({ visibility: 'visible' }) } }, 500); I tried this but didn't work: setInterval(function(){ if(cursor.style.visibility="visible"){ cursor.style.visibility="hidden"; } else{ cursor.style.visibility="visible"; } },500); Neither did this one: setInterval(function(){ if(cursor.style.display="block"){ cursor.style.display="none"; } else{ cursor.style.display="block"; } },500); Is it even possible to use pure javascript to get the same blinking effect? Both of my attempts only make it blink once.

16th Oct 2018, 6:10 PM
Fernando Moceces
Fernando Moceces - avatar
3 odpowiedzi
+ 5
Shadow is spot on By assigning the value instead of comparing then the first condition is always met Anyways, anything which is possible with jQuery is possible with vanilla js jQuery is implemented with js after all.... and for future, it will be much easier if you attached a code link for others to play with. it will be so much more convenient ;)
16th Oct 2018, 6:21 PM
Burey
Burey - avatar
+ 4
Thank you for the insights, guys! :D
16th Oct 2018, 7:23 PM
Fernando Moceces
Fernando Moceces - avatar
+ 3
Maybe it didn't work because you used the assignment operator = in the if-cases instead of the comparison operator == or ===? Also, if cursor is an id, then you will have to retrieve it first using document.getElementById('cursor') instead of only writing cursor.
16th Oct 2018, 6:18 PM
Shadow
Shadow - avatar