Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery: Click to hide element

Tags:

html

jquery

css

I have a small jQuery function below. It basically works by clicking on the element #hover-trigger, whether is be a link or image. This then makes a centralized div element appear centrally on screen, in this case #hover-content.

What I am wondering is, what function can I add onto the end of this one to make the div disappear again when a certain element is clicked?

$(document).ready(function()
{
    $('#hover-trigger').click(function()
    {
        $(this).next('#hover-content').slideToggle();
        $(this).toggleClass('active');                  

        if ($(this).hasClass('active')) 
            $(this).find('span').html('▲')
        else 
            $(this).find('span').html('▼')
    })
});
like image 829
OllyBarca Avatar asked Jun 15 '26 00:06

OllyBarca


1 Answers

whatever element you want to click on, tell it to hide the div.

$("#clickMe").click(function(){

$("#divToHide").hide();
});
like image 81
MorningDew Avatar answered Jun 17 '26 15:06

MorningDew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!