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 : 1, 2  Next

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

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

Unknown Data

Unknown Data
Registered Member
Registered Member

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

2Making Show/Hide Content Empty Re: Making Show/Hide Content Fri May 21, 2010 9:09 am

ankillien

ankillien
Administrator
Administrator
Hi Unknown Data!

So, its like a show/hide content, right?

Why are you using the Forumotion classes like "gen" and "postbody"? Please remove they since they are not useful anywhere else bu on forumotion.

One more thing, this part...
Code:
<script src="http://illiweb.com/fa/js_16/collapsible_faq.js"></script>

You should not provide URL of script hosted at illiweb.com. Instead, just ask readers to upload the script to their host and put its URL in the <script> tags because the link http:/illiweb.com/fa/js_16/collapsible_faq.js will not work if illiweb.com moves/removes the file!

Please make these changes and this tutorial will be accepted Very Happy

3Making Show/Hide Content Empty Re: Making Show/Hide Content Fri May 21, 2010 7:34 pm

Unknown Data

Unknown Data
Registered Member
Registered Member
Yay I mean a show/hide content.

I have changed it a little bit, and know it should work it better out.
And i should also work on other places than forumotion.

Hope it work. Smile

http://woops.dk

4Making Show/Hide Content Empty Re: Making Show/Hide Content Fri May 21, 2010 10:36 pm

ankillien

ankillien
Administrator
Administrator
Looks much better Very Happy

Congrats, your tutorial has been accepted.
Thank for your valuable contribution Very Happy

Tutorial Accepted

5Making Show/Hide Content Empty Re: Making Show/Hide Content Sat May 22, 2010 8:30 am

Krazy


Registered Member
Registered Member
Can you make an example available somewhere also?

6Making Show/Hide Content Empty Re: Making Show/Hide Content Sat May 22, 2010 12:56 pm

ankillien

ankillien
Administrator
Administrator
Link to the demo page added to the first post Very Happy

7Making Show/Hide Content Empty Re: Making Show/Hide Content Sat May 22, 2010 4:22 pm

latchy

latchy
Registered Member
Registered Member
Lol.

I was going to propose a tutorial about this but it's slightly different...

http://www.graphiccentral.org/

8Making Show/Hide Content Empty Re: Making Show/Hide Content Sat May 22, 2010 9:50 pm

Joel

Joel
Registered Member
Registered Member
awesome! Great tutorial dude!

http://www.advertisehotspot.info/

9Making Show/Hide Content Empty Re: Making Show/Hide Content Wed May 26, 2010 10:13 am

Russel

Russel
Moderator
Moderator
It isn't new for me but then it's great.

Congratulations!

https://www.twitter.com/russeltubo

10Making Show/Hide Content Empty Re: Making Show/Hide Content Sun Oct 24, 2010 4:26 am

Terry Harvey

Terry Harvey
Registered Member
Registered Member
Can you add the CSS for the blue box?

11Making Show/Hide Content Empty Re: Making Show/Hide Content Mon Oct 25, 2010 2:09 pm

ankillien

ankillien
Administrator
Administrator
Yes, you can. Add the style="" attribute inside the div tag.

12Making Show/Hide Content Empty Re: Making Show/Hide Content Sat Oct 30, 2010 6:01 am

verrell123

verrell123
Registered Member
Registered Member
Congratulations!

http://www.freshartz.co.cc/

13Making Show/Hide Content Empty Re: Making Show/Hide Content Sun Oct 31, 2010 4:50 pm

Plancker


Registered Member
Registered Member
Can you create it so that i f you click one an then the second the firts one closes again?

14Making Show/Hide Content Empty Re: Making Show/Hide Content Sun Oct 31, 2010 8:07 pm

ankillien

ankillien
Administrator
Administrator
Yes, it can be done. It would require some modification to this script.

15Making Show/Hide Content Empty Re: Making Show/Hide Content Wed Nov 03, 2010 10:17 pm

Plancker


Registered Member
Registered Member
Can you pleas give me a code and how to install

16Making Show/Hide Content Empty Re: Making Show/Hide Content Wed Nov 03, 2010 11:23 pm

ankillien

ankillien
Administrator
Administrator
Here is a good tutorial...
http://www.switchonthecode.com/tutorials/javascript-and-css-tutorial-accordion-menus

Here is another one...
http://www.elated.com/res/File/articles/development/javascript/document-object-model/javascript-accordion/javascript-accordion.html

17Making Show/Hide Content Empty Re: Making Show/Hide Content Thu Nov 04, 2010 7:15 am

Plancker


Registered Member
Registered Member
How do i upload Javascript to my own forum?

18Making Show/Hide Content Empty Re: Making Show/Hide Content Thu Nov 04, 2010 10:46 am

ankillien

ankillien
Administrator
Administrator
You need to upload it to a web host or you can create an HTML page on your forum and copy-paste the javascript in it.

19Making Show/Hide Content Empty Re: Making Show/Hide Content Thu Nov 04, 2010 11:32 pm

Plancker


Registered Member
Registered Member
oh like that and i can just type in "/javascript-h7.htm" for example

20Making Show/Hide Content Empty Re: Making Show/Hide Content Fri Nov 05, 2010 9:07 am

ankillien

ankillien
Administrator
Administrator
Yes, you can and if it doesn't work, add the full URL in the code.

21Making Show/Hide Content Empty Re: Making Show/Hide Content Fri Nov 05, 2010 4:38 pm

Plancker


Registered Member
Registered Member
thanks but when i add the code my background changes

22Making Show/Hide Content Empty Re: Making Show/Hide Content Mon Nov 08, 2010 8:36 am

Joel

Joel
Registered Member
Registered Member
Good one i'd say.

http://www.advertisehotspot.info/

23Making Show/Hide Content Empty Re: Making Show/Hide Content Mon Nov 08, 2010 1:25 pm

ankillien

ankillien
Administrator
Administrator
Plancker wrote:thanks but when i add the code my background changes

Where did you add the code?
Give me the link.

24Making Show/Hide Content Empty Re: Making Show/Hide Content Thu Nov 18, 2010 2:11 am

Plancker


Registered Member
Registered Member
i tried it here:

25Making Show/Hide Content 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?

Sponsored content


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

Go to page : 1, 2  Next

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