Reputation: 11
Following code is written for toggle-visibility of a submit button. Can you explain the conditional IF statement?
function ToggleVisibility(){
var b ='btn_Submit,btn_Abort_Master';
var temp = new Array();
temp = b.split(',');
var el;var i=0;
for(i=0;i<temp.length;i++){
try{
el = document.getElementById(temp[i]);
}catch(e){
try{
el = document.all[temp[i]];
}catch(e){}
}
if (el && (el = el.style) && ('string' == typeof el.visibility){
el.visibility = ('hidden' == el.visibility ? 'visible' :'hidden');
}
}
return true;
}
Upvotes: 0
Views: 52
Reputation: 2432
function ToggleVisibility(){
var b ='btn_Submit,btn_Abort_Master';
above are element on your web page taken in string (eleemnt id's)
var temp = new Array();
temp = b.split(',');
var el;var i=0;
taking an array object and splitting variable b by comma so that you will get btn_Submit,btn_Abort_Master in array. So temp[0] holds first value and temp[1] second value which are element id where toggle needs to be checked and applied.
for(i=0;i<temp.length;i++){
try{
el = document.getElementById(temp[i]);
}catch(e){
try{
el = document.all[temp[i]];
}catch(e){}
}
if (el && (el = el.style) && ('string' == typeof el.visibility){
el.visibility = ('hidden' == el.visibility ? 'visible' :'hidden');
}
}
return true;
}
looping through the temp array length and getting the element object in el. At end we are checking if element obj is present, if ele object has a style and ele object type. Inside if we are toggling visibility of element if hidden the visible and vice-versa.
Upvotes: 0
Reputation: 384
el
- if this variable is declared return true
el = el.style
- if you can to replace el with el.style return true
'string' == typeof el.visibility
- if el.visibility is a string return true
if (el && (el = el.style) && ('string' == typeof el.visibility)
- if all of these statements are true do el.visibility = ('hidden' == el.visibility ? 'visible' :'hidden');
Upvotes: 0
Reputation: 1737
Its checks the following conditions :
Upvotes: 1