Calling this code with a function...

  • 1
  • Question
  • Updated 8 years ago
  • Answered
<!--

Hi, does anyone know how to make this...

<a href="#" onclick="document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'; return false;">Click here</a>

And make it shorter, like this...

<a href="#" onclick="show_lightbox(); return false;">Click here</a>

I know it has to be in script tags and set it up with a function, but I am not that good with JavaScript yet.

Also, I need this...

<button onclick="document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'; return false;" class="close_lightbox"><font size="5" color="white">X</font></button>

To turn to this....

<button onclick="hide_lighbox(); return false;" class="close_lightbox"><font size="5" color="white">X</font></button>

Does anyone know how to do this? I am sure Kevin knows.

-->

Thanks in advance!

Nathan
Photo of Nathan

Nathan, Champion

  • 3739 Posts
  • 307 Reply Likes
  • happy

Posted 8 years ago

  • 1
Photo of jason

jason

  • 13 Posts
  • 5 Reply Likes
Official Response
I have not tested this but something like this should work:-
<!--
<script language='javascript'>
function lightbox(type) {
if (type == 'on') {
document.getElementById('light').style.display='block';
document.getElementById('fade').style.display='block';
}
else {
document.getElementById('light').style.display='none';
document.getElementById('fade').style.display='none';
}
return false;
}
</script>
-->

And then for the buttons
<!--
<button onclick='lightbox("on")'>on</button> 
<button onclick='lightbox("off")'>off</button>

-->