0

I found in web script, allowed unwind div.

function toggle(sDivId) {
    var oDiv = document.getElementById(sDivId);
    oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";
}

Whats mean that line: (oDiv.style.display == "none") ? "block" : "none";

ColBeseder
  • 3,579
  • 3
  • 28
  • 45
  • [Conditional (ternary) operator](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) – Turnip Dec 20 '16 at 15:36

3 Answers3

-1

it's a ternary operator, or "inline if" as some call it

oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";

is the same as:

if(oDiv.style.display == "none") {
    oDiv.style.display = "block";
} else {
    oDiv.style.display = "none";
}
Stu
  • 4,160
  • 24
  • 43
-1

This is ternary operator. More information here

condition ? expr1 : expr2

If condition is true, the operator returns the value of expr1; otherwise, it returns the value of expr2.

Basically, a short hand of If else statement.

if(oDiv.style.display == "none")) {
 oDiv.style.display = "block" } 
else {
oDiv.style.display = "none";}
Abhinav Galodha
  • 9,293
  • 2
  • 31
  • 41
-1

This is a ternary operator, it is basically saying the following...

Is display = "none"? If so, set "block", if not set "none"

Simply put...

Condition?true:false;

function toggle(sDivId) {
            var oDiv = document.getElementById(sDivId);
            oDiv.style.display = (oDiv.style.display == "none") ? "block" : "none";
            // Is this element display set to none? ? yes  ? no
           }
IronAces
  • 1,857
  • 1
  • 27
  • 36