Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript show() hide() jquery

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #39657
    dynamyc
    Member

    I want to hide an element by default and when a div is clicked I want to show the hidden element.
    I’m doing something like this:

    $("#searchbox").hide(); // Hide by default
    $("button").click(function() {

    My question is how to display the #searchbox when that element is clicked and hide it again when another div is clicked

    #109067
    Kitty Giraudel
    Participant

    I guess this would work, but I’m not sure I understood what you want. :D

    $('#searchbox').hide();
    $('.div-triggering-searchbox-hiding').click(function(){
    $('#searchbox').hide();
    }
    $('#button-triggering-searchbox-showing').click(function(){
    $('#searchbox').show();
    }
    #109044
    TheDoc
    Member

    CSS:

    #searchbox { display: none; }

    JS:

    $("button").click(function() {
    $("#searchbox").toggle();
    });

    By setting the default in CSS you can guarantee you won’t see it then have it flash away.

    #108991
    TheDoc
    Member

    Perfecto.

Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.