JQuery show div click to hide then do not show again?

You can rearrange your code a bit so it's unbindable (in a way that doesn't do collateral damage), like this.

You can rearrange your code a bit so it's unbindable (in a way that doesn't do collateral damage), like this: function checkShowDiv() { var top = $(window).scrollTop(); if(top >= 1000 && top , and .unbind() the check that happens on scroll that might show it again.

Thanks Nick, this works great apart from if the close button is inside the #message div... could this be achieved with . Parent ...? – Jonny Wood May 25 '10 at 13:07 @Jonny - Since you're using IDs either way it should work, but if the parent div had a classe say . CloseMe, you could do $(this).

Closest('. CloseMe'). ..but your IDs should be unique anyway, is that not the case?

– Nick Craver? May 25 '10 at 13:13 Sorry, I spoke too soon. It works perfectly!

I did think it was odd that it wouldn't work in the div, don't know what I did wrong but it's all sorted now. Thanks for your help! – Jonny Wood May 25 '10 at 13:26.

$('a#message-hide'). Click(function(e) { e.preventDefault(); // Better than returning false $('#message').remove(); // Remove the message forever }); With this you will simply remove the #message element from your page and when the user scroll to "trigger position" it'll not be displayed again.

It's worth noting this doesn't do what the OP has, his current code fades out, you would need $("#message"). FadeOut('fast', function() { $(this).remove(); });, but if the user scrolls during fadeout, there are still issues there. – Nick Craver?

May 25 '10 at 12:03.

Nick Craver answer will work only if you want to stop the div being re appeared even after user closes the div. But your code will make the div fade in continuously when you scroll bet ween 1000 and 2000. To stop the behavior, you can have a flag which indicates if the div is being displayed and check the flag before displaying the div.

Actually this would be better solved like this: $('#message:hidden'). FadeIn('slow'); I'll update the answer to handle it. – Nick Craver?

May 25 '10 at 11:59.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions