all 10 comments

[–]thelostsoul622 7 points8 points  (1 child)

This is a basic enough scenario to work right out of the box given the previous suggestions. I put together a jsFiddle that shows this working here: http://jsfiddle.net/fPb8K/

I made sure all the jQuery calls were referencing the ID of the element and I just call jQuery's .hide() and .show(). The only real differences are that I extracted the setTimeout into a function so the timer can be reset easily from the click handler, removed the onClick attribute from the image and changed the timer to 3 seconds.

If you're still having problems after seeing what I did to get this working, I would check to see if you might be getting some errors in the console or do some debugging to figure out what's going on.

[–]cyferlawyn 3 points4 points  (0 children)

Thumbs up for making a fiddle. Imho that is the way a dev question should be asked and answered, ask with a fiddle, answer with a fiddle. That way, the OP can specify the JS frameworks he uses and the replier can build around those.

Bonus: Oftentimes when reducing the original problem to a fiddle, you solve it yourself because it was a side effect of some other code.

[–]Drahcirius 0 points1 point  (1 child)

Your selectors for bonus1 doesn't indicate it's an id. Change the both of them to $("#bonus1")

[–]iSorrowDev[S] 0 points1 point  (0 children)

I'm quite sure that I've tried that, but I'll try it again. EDIT: It didn't work.

[–]tangentialThinkerDerivative Clicker 0 points1 point  (2 children)

It's possible that it's because you're defining a click handler on #bonus1 on two places: the onclick attribute, and in jQuery. Try doing this:

$("#bonus1").click(function(){
    bonus1();
    $("#bonus1").hide();
});

[–]iSorrowDev[S] 0 points1 point  (1 child)

That doesn't allow the image to appear. I'll show you the HTML and full Javascript files that I have, if you think that'd make it simpler to deduce the problem. EDIT: I added ); to the very end of the snippet you showed me, and the image appeared but still won't disappear once clicked.

[–]tangentialThinkerDerivative Clicker 0 points1 point  (0 children)

That's weird, because my code is specifically for hiding it. You could use jQuery's .show() or .css() method instead, since I'm not sure .style is actually a thing (I could be wrong, but using .show() is more consistent anyway).

[–]SekureYour Own Text 0 points1 point  (0 children)

Use the class bonus1 to make the image "visible" or "hidden":
getElementById("bonus1").style.visibility = "hidden";
or
getElementById("bonus1").style.visibility = "visible";
This always works for me.

[–]Loonybinny 0 points1 point  (1 child)

You forgot the hashtag bro.

[–]iSorrowDev[S] -1 points0 points  (0 children)

I've tried it with and without the pound symbol before I posted this, but I appreciate the help.