rss

Sunday, August 23, 2009

How To Show/Hide Text Using JavaScript Toggle Method

Show/Hide


For this method there are two steps, one is to add a code to the template </Head> </Head> region, so that you can use this anywhere [in posts, as well as widgets]

Then the second part of the code has to wherever you want to display text / images in this way.



First Step:
Log in to Blogger, go to "Layout", click on "Edit HTML" tab.
Now find for this code: </Head>

Then immediately BEFORE this code, paste this:

<script language="javascript">
function toggle() {
var ele = document.getElementById("toggleText");
var text = document.getElementById("displayText");
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "show";
}
else {
ele.style.display = "block";
text.innerHTML = "hide";
}
}
</script>


Second Step:
Now wherever you want to show this type of text, add code like this:


<a href="javascript:toggle();" id="displayText">Show/Hide</a>
<div id="toggleText" style="display: none;">This is Hidden Text</div>


here's the method to add this hack two times in your blog !

Once you have done the process described above, do this:

Third Step:
Log in to Blogger, go to "Layout", click on "Edit HTML" tab.
Now find for this code: </Head>

Then immediately BEFORE this code, paste this:


<script language="javascript">
function toggle2() {
var ele = document.getElementById("toggleText");
var text = document.getElementById("displayText");
if(ele.style.display == "block") {
ele.style.display = "none";
text.innerHTML = "show";
}
else {
ele.style.display = "block";
text.innerHTML = "hide";
}
}
</script>


Fourth Step:
Now wherever you want to show this type of text, add code like this:


<a href="javascript:toggle2();" id="displayText">Show/Hide</a>
<div id="toggleText" style="display: none;">This is Hidden Text</div>




Similarly you can add any number of times, by changing the code in red to toggle3(), toggle4() etc.
But if you add it many times, then it may slow down your blog !
Stumble Delicious Technorati Twitter Facebook
If you enjoyed this post, make sure you subscribe as an Reader!

0 comments:


Post a Comment

← Newer Post Older Post → Home
 

Recent Posts

Recent Comments

Follow Me

UseAds.com - Advertise your site at UseAds.com! Submit your site and get tons of traffic!
UseAds.com - Advertise your site at UseAds.com! Submit your site and get tons of traffic!