Skip to content
Advertisement

Hide/Show image after 2 seconds

So I need to have an image alternatively appear and disappear every 2 seconds, I’ve been trying using javascript and I’ve gotten stuck, I feel like it’s something so simple but i can’t work it out, any help is appreciated.

HTML

JavaScript

JAVASCRIPT

JavaScript

Advertisement

Answer

You need to use callback functions in your setInterval.

I changed your JavaScript to this:

JavaScript

here is a JSFIDDLE as well.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement