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?
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?
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.
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
If you are using jQuery .
$('#sua-div').css('visibility', 'hidden');
If you are using JavaScript .
document.getElementById('sua-div').style.visibility = 'hidden';
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
complemented above, if you are using angularJS.
<div id="panel" ng-show="false">