title: Javascript loop of if statement
body: <p>I'm trying to shorten my function that contains a number of if statements into a loop function but just can't seem to get it to work. It is currently working in Google Tag Manager as a Custom Javascript Macro.</p>
  
  <p>I'm not a developer or very good at Javascript so any help will be greatly appreciated.</p>
  
  <p>Code:</p>
  
  <pre><code>  function()
    {
    if(document.getElementById('bfPage1').style.display !== "none")
       {return document.getElementById('bfPage1').getAttribute('id');
       }
    else
       if(document.getElementById('bfPage2').style.display !== "none")
          {return document.getElementById('bfPage2').getAttribute('id');
          }
       else
          if(document.getElementById('bfPage3').style.display !== "none")
             {return document.getElementById('bfPage3').getAttribute('id');
             }
          else
             {return document.getElementById('bfPage4').getAttribute('id')
             }
    }
  </code></pre>
  
  <p>Thanks in advance.</p>