360

professional dilettante

Easy show / hide with JavaScript and CSS

Easily show and hide content using JavaScript and CSS. If the demo on this page does not work, another version of the demo is here:http://cdia.zhannes.webfactional.com/js/toggle.php

>>Clicking here will show / hide the content below, depending on what the current class is.

Phasellus non turpis orci. Nulla dignissim ultrices blandit. Nulla facilisi. Morbi condimentum posuere bibendum. Duis a nibh vehicula turpis auctor aliquet ac non massa. Vestibulum vel felis lacus, vitae gravida est. Aliquam imperdiet massa non erat congue rhoncus. Duis pretium consectetur turpis vel varius. Etiam varius iaculis dapibus. Phasellus elit metus, tempor eu viverra a, eleifend sit amet orci.

the code looks like this

function toggle(theID) {
var obj = document.getElementById(theID);
if (obj.className == "show") {
obj.className="hidden";
} else {
obj.className="show";
}
}

where the param passed to the function, theID, is the CSS ID (#something) element you want to read and set. You just need to attach and event handler to an element, such as an empty link, like this:

onclick=”toggle(‘content’);” 1

1Hoping to get syntax highlighting soon…

and the CSS for the classes added to the elements looks like:

.hidden {display:none; visibility:hidden; }
.show {display:block;visibility:visible;}

One Response

You can follow the comments for this article with the RSS 2.0 feed.

Thank you very much!!

Thats a simple and easy template to work with.

1 Christian (Austria) December 29, 2009 4:24 pm

Leave a Reply

Required fields are marked with an asterisk (*), you may use these tags in your comment: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Spam protection by WP Captcha-Free

Most Recent Post

It’s been a long time, I shouldn’t have left you, part 1 …

But now I’m back.All official like.I do social stuff again.I see my friends.I’m moving into my own place again.And all that adult shit.

Categories

Content © professional dilettante
Proudly powered by WordPress
Theme designed by Artisan Themes

Entries (RSS)
Comments (RSS)

22 queries.
0.514 seconds.