Aham... there's a thing called PARAMETERS. If you change your function
to something like this, it might function:
<script type="text/javascript">
function change(thisdiv) {
var check = 0;
var button = document.getElementById(thisdiv);
if ( check == 0 ) {
button.style.background="green";
check = 1;
} else {
button.style.background="red";
check = 0;
}
}
</script>
<div class="navbutton" id="a_button" onclick="change(a_button);">
<span class="navbutton_text">button 1</span>
</div>
<div class="navbutton" id="another_button"
onclick="change(another_button);">
<span class="navbutton_text">button 2</span>
</div>
On Mon, Dec 22, 2008 at 3:20 PM, Bazley <[email protected]> wrote:
>
> Is it possible to have a single function controlling multiple buttons
> for which the color of each can be individually switched back and
> forth between two different colors? The following code works fine for
> a single button, but for more than one button it fails. The function
> change() needs to be able to distinguish between buttons. Passing the
> button that is clicked to the function would work, is that possible
> somehow?
>
> <script type="text/javascript">
> var check = 0;
> function change() {
> var button = document.getElementById('a_button');
> if ( check == 0 ) {
> button.style.background="green";
> check = 1;
> } else {
> button.style.background="red";
> check = 0;
> }
> }
> </script>
>
> <div class="navbutton" id="a_button" onclick="change();">
> <span class="navbutton_text">button 1</span>
> </div>
>
> <div class="navbutton" id="a_button" onclick="change();">
> <span class="navbutton_text">button 2</span>
> </div>
>
> >
>
--
André Ferreira
[email protected]
--~--~---------~--~----~------------~-------~--~----~
--
You received this because you are subscribed to the "Design the Web with CSS"
at Google groups.
To post: [email protected]
To unsubscribe: [email protected]
-~----------~----~----~----~------~----~------~--~---