Google Groups Home
Help | Sign in
show/hide javascript
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
dylanb  
View profile
 More options May 9, 3:48 pm
Newsgroups: comp.lang.javascript
From: dylanb <dylanbu...@gmail.com>
Date: Fri, 9 May 2008 12:48:48 -0700 (PDT)
Local: Fri, May 9 2008 3:48 pm
Subject: show/hide javascript
Hi can anyone tell me how to alter this script so it will works on
classes and id's;
<script>
function showhide(id){
if (document.getElementById){
obj = document.getElementById(id);
if (obj.style.display == "none"){
obj.style.display = "";
} else {

obj.style.display = "none";
}
}
}

</script>

its called by;

<a href="javascript:void(0)" onmouseover="showhide('divname')">
link</a>

<div style="display: none;" id="divname">
some content
</div>

I just need to make it work on div classes


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thomas 'PointedEars' Lahn  
View profile
(1 user)  More options May 9, 5:12 pm
Newsgroups: comp.lang.javascript
From: Thomas 'PointedEars' Lahn <PointedE...@web.de>
Date: Fri, 09 May 2008 23:12:47 +0200
Local: Fri, May 9 2008 5:12 pm
Subject: Re: show/hide javascript

dylanb wrote:
> Hi can anyone tell me how to alter this script so it will works on
> classes and id's;
> <script>

  <script type="text/javascript">

> function showhide(id){
> if (document.getElementById){
> obj = document.getElementById(id);
> if (obj.style.display == "none"){
> obj.style.display = "";
> } else {
> obj.style.display = "none";
> }
> }
> }

A bit more indentation would make this script legible, but not good.
For example, `obj' was not declared and so is not local; it should be

  var obj = ...

instead.

> </script>

> its called by;

> <a href="javascript:void(0)" onmouseover="showhide('divname')">
> link</a>

Should be at least

  <script type="text/javascript">
    document.write('<a href="javascript:void(0)" onclick="return false"'
     + ' onmouseover="showhide(\'divname\')">link<\/a>');
  </script>

so that no-script users are not bothered with a non-working element.

> <div style="display: none;" id="divname">
> some content
> </div>

It is a really bad idea to hide content first.  This way it will stay
inaccessible when there is insufficient script and DOM support available.

> I just need to make it work on div classes

Since unlike an ID a CSS class may be used for several elements in a
document, the solution is a not a trivial one.  See e.g.
dhtml.getElemByClassName() in http://PointedEars.de/scripts/dhtml.js

Another way is to apply the XPath expression `//*[@class="foo"]' on the BODY
node or a decendant node, see <http://developer.mozilla.org/en/docs/XPath>.
(This will be implemented in the next version of dhtml.js.)

PointedEars
--
    realism:    HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness:    XHTML 1.1 as application/xhtml+xml
                                                    -- Bjoern Hoehrmann


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google