Show and hide div - Prototype with XhochY modification

The goal is to look if the modified Prototype actually works. Let's make an object hide and show on user action.

hide

this is a test object which should hide and show on user action

I created an action link and object on which action will be taken. I gave them ids test_hide and test_hide_button

Prototype accesses the DOM elements using $(id_name) function. Because it is a modification, I have to use $ID(id_name).

Example uses hide() and show() Prototype functions.

<a id='test_hide_button' onclick="showhide('test_hide')">hide</a>
<p id='test_hide'>this is a test object which should hide and show on user action</p>

<script type='text/javascript'>
function showhide( id ) {
  if ($ID(id).hidden) {
    $ID(id).show();
    $ID(id).hidden = false;
    $ID(id + '_button').innerHTML = 'hide';
  } else {
    $ID(id).hide();
    $ID(id).hidden = true;
    $ID(id + '_button').innerHTML = 'show';
  }
}
</script>

Trackback URL for this post:

http://piotr.zalewa.info/trackback/8