Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

document class question 1

Status
Not open for further replies.

osbel

Programmer
Sep 17, 2001
26
0
0
US
I am building a site that has a menu page that is called from many different pages so that to change the menu only the one file must be changed. In some of the pages I have set a css class. How do I check to see if the class has been defined before i try to use it? I have tried this.document.styles.class_name but it doesn't work. Any ideas? Thanks.
Leslie
 
try

this.className

that will alert the classname of the element in focus. test it with this...
Code:
<a href=&quot;#&quot; class=&quot;myClass&quot; onclick=&quot;alert(this.className); return false;&quot;>click it go on you know you want to!!</a>

hope this helps

:)
 
That helps a little, but not exactly waht I am looking for. Maybe this will make it easier. i want to be able to make a class called hideme that I can set as the class for specific objects that I want to hide and unhide using javascript. for example:
<style type=&quot;text/css&quot;>
*.hideme {display: inline}
</style>

<script>
function hide_stuff() {
(1) change the class hideme to have: display: none;
}
function show_stuff() {
(2) change the class hideme to have: display: inline;
}
</script>
Does anyone know what code to put in to lines (1) and (2)? Thanks.
Leslie
 
I just figured it out. Use this code for the javascript:
function hide_elements() {
document.styleSheets[0].rules.item(0).style.display = &quot;none&quot;;
}

function show_elements() {
document.styleSheets[0].rules.item(0).style.display = &quot;inline&quot;;
}

Now, does anyone know how to hide a form element or object and not have all of the elements below it move up?
Leslie
 
Thanks that does exactly what I wanted.
Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top