About Me

My photo
Horsham, Victoria, Australia
Just A Reflection Of Myself--- Became a Blogger through IT Studies

Tuesday, January 6, 2009

Experimental JavaScript

Well as I have blogged before about my Live Spaces account and the reasons we parted company. Today I though i would experiment with JavaScript in a blog. JavaScript is a a client side scripting language for web pages

I am going to do a simple show hide method to show and hide some text inside a div tag.

This is easily done by using the visibility style of the the div tag.

You could place any html in you div tag that makes for some interesting effects and if able to do this in my blogger account  then I can do some really cool stuff.

First of all we need to define some styles using Cascading Style Sheet 'CSS' . We are going to use 2 classes 1 to show the div (showdiv) and the other to hide the div(hidediv).

<style>

.showdiv {visibility:visible}

.hidediv {visibility:hidden}

</style>







The step is to create our JavaScript method to change the class of the tag when we select an element that will show and hide the div.




<script language="javascript" type="text/javascript"> 
function ShowCode()
{
var d=document.getElementById("Code");
if(d.className =="hiddendiv")
{
d.className='showdiv';
}
else
{
d.className='hiddendiv';
}
}

</script>











An that is it. No all we do now is create the div and provide a method to show and hide it.



<div class="hiddendiv" id="Code"> 

<h1> Hello World</h1></div>



Click this


beginplus

Hello World



Well  I did not work.



I havent given up thou becaust wen I look at the code behind the JavaScript is still there unlike Live Space

No comments:

Post a Comment