title: Close a window with JavaScript onClick
body: <p>On my website I have 4 Windows (identified by target1, target2, target3 and target4). On these Windows I want to add a button with a name of "close" and using an onClick event call the correct function depending on which window.</p>
  
  <pre><code>function close_window1(){
      document.getElementById('target1').style.display = 'none';  
  }
  
  function close_window2(){
      document.getElementById('target2').style.display = 'none';  
  }
  
  function close_window3(){
      document.getElementById('target3').style.display = 'none';  
  }
  
  function close_window4(){
      document.getElementById('target4').style.display = 'none';  
  }
  </code></pre>
  
  <p>I'm sure there is a better way than this:</p>
  
  <pre><code>function close_window(){
      $(this).parents('div').style.display='none'
  }
  </code></pre>
  
  <p>This will close only the window that has the event, but it doesn't work.</p>
  
  <p>Could someone help me please?</p>