Make div disappear

2

I have a code that only works if I keep a <div id="panel"> , but I do not want it to appear on the screen. Can you keep this div, but leave it invisible?

    
asked by anonymous 12.08.2015 / 15:54

5 answers

2

Or in CSS itself:

<div id="panel" style="visibility:hidden;"></div>

or

#panel { visibility:hidden; }

It just does not make much sense, or I do not quite understand it.

    
12.08.2015 / 16:02
2

To make invisible / hide the div you can do this:

$("#panel").hide() ou $("#panel").css("display", "none")

The problem is if you are doing some validation to check that div is visible:

$("#panel").is(":visible")

Then you will have to change the validation to check that div exists:

if($("#panel").length > 0)
   //div existe
    
12.08.2015 / 16:02
1

If you are using jQuery .

$('#sua-div').css('visibility', 'hidden');

If you are using JavaScript .

document.getElementById('sua-div').style.visibility = 'hidden';

    
12.08.2015 / 15:57
1

If you use style="display:none;" your div will be there, but it will not be visible. See below for an example.

function mostraDiv(id,div2)
{
var divstyle = new String();        
divstyle = document.getElementById(id).style.display;

var divAux = new String();        
divAux = document.getElementById(div2).style.display;
      
      if (divAux=="block" || divAux == ""){
	   document.getElementById(div2).style.display = "none";
	}   
	
	document.getElementById(id).style.display = "block"; 
	return false;  
}
<a href="#" onclick="displayDiv('teste','teste2')"> </a> 
<a href="#" onclick="displayDiv('teste2','teste')"> </a> 

<div id="teste">
  teste
</div>

<div id="teste2" style="display:none;">
  teste2
</div>

Source: This post

    
12.08.2015 / 16:02
1

complemented above, if you are using angularJS.

<div id="panel" ng-show="false">

    
12.08.2015 / 16:12