View Full Version : Changing button content and link when clicked

07-15-2009, 10:53 PM
Hi all,

I am running a website and I want to display many things on the same page. Currently what I have is something like this:

[two buttons here]

[some code here, showing]

[some code here, hiding]

When i click the second button, the hidden code replaces the code that was just showing. The first button then re-hides that code and shows the first code again. What I want to do is combine the two buttons so that when you click the first one, the text and hyperlink will change to display that of the second button. And when you click the button again, it will change to the text and hyperlink of the first button.

I know I'm being really confusing here (while rereading what i typed, even I myself was confused) but i hope I can get my point out to you. Thanks a lot for your help!

07-15-2009, 10:59 PM
Any help please!

07-16-2009, 07:29 AM
I think all modern browsers recognize "inline-block" for CSS "display".

So if text2 is positioned over text1, and text2 starts out hidden, your button would just toggle text2 between display:none and display:inline-block.

Just use the 'conditional operator', the inline branch,

onclick="var d2=document.getElementById('text2');d2.style.display = d2.style.display!=='inline-block' ? 'inline-block' : 'none';"

[Better though to assign in your script to the 'click' button using the setAttribute() method than hardcode into the HTML page, as a general rule.]