WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You

WebArtz - The Web Design Forum
Welcome to WebArtz, Guest!

WebArtz is a nice place for discussions related to web designing and coding. We help our members to code their own website templates with HTML and CSS. We give them advice on various issues.

To know more about WebArtz Forum, visit the About Us page.

At the moment, you are viewing the forum as a guest. As a guest you can't make post and participate in discussions. You need to register and become a member of the forum. Click the register link below and become a part of this forum.

Thank You


You are not connected. Please login or register

Go to page : Previous  1, 2

View previous topic View next topic Go down  Message [Page 2 of 2]

1Making Show/Hide Content - Page 2 Empty Making Show/Hide Content Thu May 20, 2010 10:00 pm

Unknown Data

Unknown Data
Registered Member
Registered Member
First topic message reminder :


Making Show/Hide Content
Showing and hiding content on mouse click!

A simple and good JavaScript function to know, is how to make a show and hide function.

This can easily be done if you know just a little JavaScript, or some basic HTML/CSS + english.

Let start out with taking a look at the function:
Code:
function mytoggle(elm) {
   var module = document.getElementById(elm);
   if (module.style.display == "none") {
      module.style.display = "block";
   }
   else {
      module.style.display = "none";
   }
}
So what does the function do?

We start out with declaring a JavaScript function with an selection inside the parameter (this means that we can find the element within an event handler, and have multiple toggles on the page). Next, we create a variable to shorten out the length of the JavaScript. This means that the variable module, is equal to document.getElementById(elm).

Now we start out with creating an if and else statement. First we check if the elm from the parameter is hidden, and if that is true, we are manipulating with it's style, and make it visible. But if it's false, then we can conclude that the element must be visible, and therefore are we instead changing it's display-property to none, eq. hiding it. And that's about it.

So how do we use the function?

Well, that's an easy one. We can activavte it through a event handler or other JavaScript functions, by simply change the parameter to the ID of the element that should be toggled.
So if we write mytoggle("randomelement"), will the element with the ID of randomelement be toggled.

A quick example could look like this (modify it for own use, or reply to this topic, if you want help):
Code:
<script type="text/javascript">
function mytoggle(elm) {
   var module = document.getElementById(elm);
   if (module.style.display == "none") {
      module.style.display = "block";
   }
   else {
      module.style.display = "none";
   }
}
</script>

<a href="javascript:mytoggle('visiblediv');">Toggle div</a>
<div id="visiblediv">Content of one element to toggle.</div>

<a href="javascript:mytoggle('hiddendiv');">Toggle div</a>
<div id="hiddendiv" style="display: none;">Content of another element to toggle.</div>

To see the demo of this code : Click Here
Notice : This tutorial is copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators.



Last edited by Unknown Data on Tue Jun 19, 2012 12:25 am; edited 5 times in total

http://woops.dk

26Making Show/Hide Content - Page 2 Empty Re: Making Show/Hide Content Sat Nov 20, 2010 2:56 am

Plancker


Registered Member
Registered Member
he asks link i give link what's wrong?

27Making Show/Hide Content - Page 2 Empty Re: Making Show/Hide Content Sat Nov 20, 2010 8:56 am

Jophy

Jophy
Registered Member
Registered Member
Sorry, I didn't noticed that, just re-edit your post.

(I need my eyeglasses No )

http://www.socialtechforum.com/

Sponsored content


View previous topic View next topic Back to top  Message [Page 2 of 2]

Go to page : Previous  1, 2

Permissions in this forum:
You cannot reply to topics in this forum