Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8376929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:32:42+00:00 2026-06-09T15:32:42+00:00

I have set a div to hide with fading effect on document click, It

  • 0

I have set a div to hide with fading effect on document click, It hides on clicking any where but the problem is it reappears on another click and then go to hide, it should not reappear on the any another click.

I have tried like this.

Javascript Code

    <script type="text/javascript">
var fired = false;
if(!fired){
document.onclick=function(){close_box_fadeOut()};
delete this.onclick;
}var fired = true;
function close_box(){
    document.getElementById("search-result").style.display="none";
}
function close_box_fadeOut(){
    setOpacity( 100 );
    document.getElementById("search-result").style.display="block";
    fadeOut();
    setTimeout(close_box, 800);
}
function setOpacity( value ) {
 document.getElementById("search-result").style.opacity = value / 10;
 document.getElementById("search-result").style.filter = 'alpha(opacity=' + value * 10 + ')';
}
function fadeOut() {
 for( var i = 0 ; i <= 100 ; i++ ) 
   setTimeout( 'setOpacity(' + (10 - i / 10) + ')' , 8 * i );
}
</script>
enter code here

html Code

<div id="search-result"></div>

and Css Code

<style>
  #search-result{
width: 500px;
height: 25px;
background:#069;
border: 5px solid #000;
display: block;
   }
</style>

Please see and suggest any possible way to do this.

Thanks

Instant Search Codes

    function showResult(str)
{
if (str.length==0)
{
document.getElementById("search-result").innerHTML="";
document.getElementById("search-result").style.border="0px";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("search-result").innerHTML=xmlhttp.responseText;
document.getElementById("search-result").style.border="1px solid #A5ACB2";
document.getElementById("search-result").autocomplete="off";
document.getElementById("search-result").style.display="block";
var fired  = false;
var fade = false;
document.onclick = function(){
close_box_fadeOut();
if(!fade){
document.getElementById("search-input").onmouseenter = function(){
show_box_fadeIn()
delete this.onmouseenter;};
  };
}
document.getElementById("search-input").onmouseleave = function(){
var fade = true;
if(fade){
document.getElementById("search-input").onmouseenter = function(){
show_box()};
 };
}
document.getElementById("search-input").onclick = function(e){
    if(!e) {
    e = window.event;
    }

    if(e.stopPropagation && e.preventDefault) {
    e.stopPropagation();
    e.preventDefault();
    } else {
    e.cancelBubble = true;
    e.returnValue = false;
    }show_box(); return true;
};
}
}
xmlhttp.open("GET","instant-search.php?keyword="+str,true);
xmlhttp.send();
}
function close_box(){
document.getElementById("search-result").style.display="none";
}

function close_box_fadeOut(){
if(fired ){
return;
}
fired = true;
setOpacity( 100 );
document.getElementById("search-result").style.display="block";
fadeOut();
setTimeout(close_box, 800);
}
function show_box(){
document.getElementById("search-result").style.display="block";
}
function show_box_fadeIn(){
setOpacity( 0 );
document.getElementById("search-result").style.display="block";
fadeIn()
}
function setOpacity( value ) {
document.getElementById("search-result").style.opacity = value / 10;
document.getElementById("search-result").style.filter = 'alpha(opacity=' + value * 10 + ')';
}
function fadeIn() {
for( var i = 20 ; i <= 100 ; i++ )
setTimeout( 'setOpacity(' + (i / 5) + ')' , 5 * i );
}
function fadeOut() {
//for( var i = 20 ; i <= 100 ; i++ )
//setTimeout( 'setOpacity(' + (5 - i / 5) + ')' , 5 * i );
for( var i = 0 ; i <= 100 ; i++ ) 
setTimeout( 'setOpacity(' + (10 - i / 10) + ')' , 8 * i );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:32:43+00:00Added an answer on June 9, 2026 at 3:32 pm

    The function registered with document.onclick is called whenever there is a click, regardless of whether or not fired is false. You need to check if fired is false inside of your close_box_fadeOut() function or somewhere else during that called click function.

    For example:

    function close_box_fadeOut(){
        if(fired){
            return;
        }
        setOpacity( 100 );
        document.getElementById("search-result").style.display="block";
        fadeOut();
        setTimeout(close_box, 800);
    }
    

    Edit: Here’s how I would change all of your code to work:

    <script type="text/javascript">
    var fired = false;
    
    document.onclick=function(){close_box_fadeOut()};
    
    function close_box(){
        document.getElementById("search-result").style.display="none";
    }
    function close_box_fadeOut(){
        if(fired){
            return;
        }
        fired = true;
        setOpacity( 100 );
        document.getElementById("search-result").style.display="block";
        fadeOut();
        setTimeout(close_box, 800);
    }
    function setOpacity( value ) {
     document.getElementById("search-result").style.opacity = value / 10;
     document.getElementById("search-result").style.filter = 'alpha(opacity=' + value * 10 + ')';
    }
    function fadeOut() {
     for( var i = 0 ; i <= 100 ; i++ ) 
       setTimeout( 'setOpacity(' + (10 - i / 10) + ')' , 8 * i );
    }
    </script>
    

    Edit 2: Here’s what your on click should look like.

    document.onclick = function(){
        if(fade){
            return;
        }
    
        document.getElementById("search-input").onmouseenter = function(){
            show_box_fadeIn()
            delete this.onmouseenter;
        };
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a very basic hide/show div function set up for when people click
I have set a fix height of DIV and set its overflow-y:scroll but the
I have set the data to div element and append it to another div
Hi all I have problem with my div's in html. I have set them
I have a basic jQuery tabs system going: $(document).ready(function(){ $('#tabs div.jdiv').hide(); $('#tabs div.jdiv:first').fadeIn(slow); $('#tabs
I have a div, I want to set it so that when I click
i have this tab-system: $(document).ready(function(){ $('#tabs div').hide(); $('#tabs div:first').show(); $('#tabs ul li:first').addClass('active'); $('#tabs ul
I have set up a div however the image inside of it exceeds its
I have a div set transparent with rgba and want on that div an
I have set the target of the pic_form to a div (pic_target). The form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.