SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    DHTML visibility problem

    Can someone please tell me what's wrong with this code:


    ----------------------------------------------------------------
    <div id="moj" style="position:absolute; top: 100px; left: 200px; visibility: visible;">
    a
    </div>

    <script>
    function dom(id) {return document.getElementById(id).style}
    dom('moj').visibility = 'visible';

    function toggleVis() {
    if (dom('moj').visibility = 'visible') {dom('moj').visibility = 'hidden';}
    else if (dom('moj').visibility = 'hidden') {dom('moj').visibility = 'visible';}
    else {dom('moj').visibility = 'visible';}
    }
    </script>

    <button onclick="toggleVis();">Click me!</button>
    ----------------------------------------------------------------


    when I click the button, the div disappears, but when I click it again, the div doesn't show .

    And aonther thing. When an object is invisible... Is it still there? Let my present an example: you have a div, that has visibility: hidden and has a mouseover attribut that sets the visibility of the div to visible. Does the div appear when you roll your mouse over that div?
    Last edited by Rok; Aug 29, 2002 at 05:44.

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Here's that example

    I forgot to link my file:
    link

  3. #3
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to have two equal signs for your if statement like this:
    if (dom('moj').visibility == 'visible') {dom('moj').visibility = 'hidden';}

    Correct that and your script should work. It is a simple mistake. I make them all the time.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dammit . How could I have overlooked this?!

    Thanks man!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •