Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    50
    Member #
    31189

    hide/unhide script

    Hello -

    I'm trying to "pair" the following js script with css presentational scheme

    the js:
    /*has its own built-in css*/
    <style>
    <!--
    .hidden { display: none; }
    .unhidden { display: block; }
    -->
    </style>
    <script type="text/javascript">
    function unhide(divID) {
    var item = document.getElementById(divID);
    if (item) {
    item.className=(item.className=='hidden')?'unhidde n':'hidden';
    }
    }
    </script>
    </head>

    <body>
    <div id="col2">
    <a href="javascript:unhide('content_title');">
    <font face="Century Schoolbook" color="#000000">Content title</font></a>
    </font></div>
    <div id="col2">
    <div id="content_title" class="hidden">
    <p style="margin-bottom: 0">
    Actual content here.
    </p>
    </div>
    the (base) css:
    .hidden li {
    background: #fff;
    padding: 3px 8px;
    display: table-row;
    line-height: 500%;
    font: 20px century schoolbook, serif;
    transition: background .25s ease-in-out;
    -moz-transition: background .25s ease-in-out;
    -webkit-transition: background .25s ease-in-out;
    }
    .hidden li:hover {
    background: #ddd;
    text-decoration:underline;
    }
    Now my combination comes out to this essentially:
    <style>
    <!--
    .hidden {
    display: none;
    text-decoration: none;
    background: #fff;
    }

    a.hidden :hover {
    background: #ddd;
    text-decoration:underline;
    padding: 3px 8px;
    line-height: 100%;
    font: 20px century schoolbook, serif;
    transition: background .25s ease-in-out;
    -moz-transition: background .25s ease-in-out;
    -webkit-transition: background .25s ease-in-out;
    }

    .unhidden {
    display: block;
    font: 20px century schoolbook, serif;
    }
    -->
    </style>
    <script type="text/javascript">
    function unhide(divID) {
    var item = document.getElementById(divID);
    if (item) {
    item.className=(item.className=='hidden')?'unhidde n':'hidden';
    }
    }
    </script>
    </head>

    <body>
    <ul class="cities"> //needed for the desired indent on the page
    <div id="col2">
    <a href="javascript:unhide('content_title');">
    <font face="Century Schoolbook" color="#000000">Title of Content</font></a></div>

    <div id="col2">
    <div id="content" class="hidden">
    <p style="margin-bottom: 0">
    Actual Content.
    </p>
    </div>
    <div id="content"> works fine. The "unhide('content_title') is unresponsive to the a.hidden :hover css. There has to be a way to get that part to "respond". I can induce changes to other parts of the script; I just can't do it to this particular section. Please help. Thanks!
    Last edited by acegreen; Sep 07th, 2013 at 11:38 AM.

  2.  

  3. #2
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    a.hidden isn't in your HTML anywhere. div.hidden is (since your content div is hidden), but not a.

    If you want to use an effect on that link specifically, do something like this.

    <a href="javascript:unhide('content_title');" id="title-link">

    And then for your CSS, change a.hidden:hover to a#title-link:hover . Then you'll get some of what you want. Your link won't unhide your content div when you click on it, but that'll be another puzzle for you to try and solve.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  4. #3
    Member
    Join Date
    Mar 2012
    Posts
    50
    Member #
    31189
    Quote Originally Posted by TheGAME1264 View Post
    a.hidden isn't in your HTML anywhere. div.hidden is (since your content div is hidden), but not a.

    If you want to use an effect on that link specifically, do something like this.

    <a href="javascript:unhide('content_title');" id="title-link">

    And then for your CSS, change a.hidden:hover to a#title-link:hover . Then you'll get some of what you want. Your link won't unhide your content div when you click on it, but that'll be another puzzle for you to try and solve.
    I tried these variations and really couldn't get anywhere. I went over on stackoverflow and sort of refined the script but now it sort of does the OPPOSITE of what is needed. From jsfiddle here is what I have:


    css:
    a.unhide li {
    background: #fff;
    padding: 3px 8px;
    display: table-row;
    line-height: 500%;
    font: 20px century schoolbook, serif;
    transition: background .25s ease-in-out;
    -moz-transition: background .25s ease-in-out;
    -webkit-transition: background .25s ease-in-out;
    }
    .unhide:hover { background: #ddd; padding: 3px 8px; display: table-row; line-height: 500%; font: 20px century schoolbook, serif; transition: background .25s ease-in-out; -moz-transition: background .25s ease-in-out; -webkit-transition: background .25s ease-in-out; }
    .hide {
    font: 20 px century schoolbook, serif;
    color: black;
    text-decoration: none;
    }
    .unhide {
    font: 20 px century schoolbook, serif;
    color: red;
    text-decoration: none;
    }
    .js
    function unhide(divID) {
    var item = document.getElementsByClassName(divID)[0];
    console.log(item);
    console.log(item.className == divID + ' hide');
    if (item) {
    item.className = (item.className == divID + ' hide') ? divID + ' unhide' : divID + ' hide';
    }
    }
    php
    <div>
    <a href="javascript:unhide('content1');">
    Title of Content</a>

    </div>
    <div>
    <div class="content1 hide">Body of content</div>
    </div>
    This works for the most part. Expect I'm trying to get the hover effect to hit "Title of Content". At the moment the hover effect hits "Body of content".
    Also "Title of Content" is always underlined, and blue. I want it black, and underlined only on a hover. Any thoughts?
    Please help.

  5. #4
    Unpaid WDF Intern TheGAME1264's Avatar
    Join Date
    Dec 2002
    Location
    Not from USA
    Posts
    14,483
    Member #
    425
    Liked
    2783 times
    You're making the same mistake you did the first time, dude. Anything you apply to a.unhide in your CSS will only work if you assign a class of .unhide to your a tag. You haven't, so there's no effect.

    Put the variations back in exactly as I told you to put them in, upload it somewhere, and show us where you're at. It's going to work out a whole lot faster if you do that.
    If I've helped you out in any way, please pay it forward. My wife and I are walking for Autism Speaks. Please donate, and thanks.

    If someone helped you out, be sure to "Like" their post and/or help them in kind. The "Like" link is on the bottom right of each post, beside the "Share" link.

    My stuff (well, some of it): My bowling alley site | Canadian Postal Code Info (beta)

  6. #5
    Member
    Join Date
    Mar 2012
    Posts
    50
    Member #
    31189
    Quote Originally Posted by TheGAME1264 View Post
    You're making the same mistake you did the first time, dude. Anything you apply to a.unhide in your CSS will only work if you assign a class of .unhide to your a tag. You haven't, so there's no effect.

    Put the variations back in exactly as I told you to put them in, upload it somewhere, and show us where you're at. It's going to work out a whole lot faster if you do that.
    Hey - Here's a tinyurl for the script and an explanation of what I'm trying to accomplish. The "plain" link (that I want to jazz) up works on this. I believe it's a pretty good explanation honestly. And concise, too.

    Cities & Towns

    PS just realized a.unhide really wouldn't be necessary (since the mouseover effect isn't necessary on the active unhide link, it's on whichever unhide link the cursor is over).
    It would only be .unhide, .unhide :hover, and .hidden.
    Last edited by acegreen; Sep 09th, 2013 at 01:53 AM. Reason: .unhide, .unhide :hover, .hidden


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:31 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com