Tuesday, March 17, 2015

Conditional Ternary Operator:


Conditional Ternary Operator:



I saw couple of people suggested in the Stack overflow forum for hiding the HTML elements using below code.

if countryName == "INDIA" {
document.getElementById("test").style.display = ""
}
else{
document.getElementById("test").style.display = ''none.
}

I would like to suggest for hiding HTML Elements using Conditional Ternary operator.  Just try the below line for showing or hiding the HTML Elements

test ? expression1 : expression2


Example:
document.getElementById("test").style.display = (CountryName=="INDIA" ? "" : 'none')


No comments:

Post a Comment