Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Div fade out when clicked

Featured Replies

Hey!

 

I have created some code, so when I click on an image with the id="preview1" a div with the id="preview1info" will appear, now that would according to plan.

 

But where I am struggling is how would I get the 'preview1info' div to disappear when clicked on?

 

here's the code -

 

<img src="images/preview.png" alt="preview image" id="preview1">
<div id="preview1info">
</div>
<script type="text/javascript">
$('#preview1info').hide(); // Initially hide info
$('#preview1').click(function() { // Show on click
    $(this).next('#preview1info').fadeIn();
});
</script>

 

Thanks in advance

  • Author

$('#previewinfo1').click(function(){

$('#previewinfo1').fadeOut();

});

 

Might do it? I've not tested it as I'm posting from my mobile.

That didn't work but I found a solution, for when I click outside the div it will hide.

 

 

$(document).mouseup(function (e)
{
var container = $("#preview1info");
if (!container.is(e.target) // if the target of the click isn't the container...
&& container.has(e.target).length === 0) // ... nor a descendant of the container
{
container.hide();
}
});

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.