January 27th, 2013, 02:42 AM
Join Date: Oct 2012
Time spent in forums: 11 h 16 m 38 sec
Reputation Power: 1
Why doesn't this function work by the first click??
I have this JS code to just demonstrate how to show and hide a content by clicking text.
This basically work but only after the second click. When you refresh the page and click on the "Click me please" text, it doesn't seem to fire up the function "changeButton()".
Can anyone explain exactly why, please?
So please someone help me..
var grabHiddenOrShownArea = document.getElementById('hidden_or_shown_area');
if( grabHiddenOrShownArea.style.display == 'block')
var displayValue = 'none';
var displayValue = 'block';
grabHiddenOrShownArea.style.display = displayValue;
<!-- this is button to fire up the function -->
<a href="#" id="hit_this_button" onclick="changeButton()">Click me please.</a>
<!-- shown or hidden area -->