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.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 19
  1. #1
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    What is a "universal" (i.e., IE5.5+/NS6+/Moz) way of hiding or showing a given id; for example:
    Code:
    <span id="myspan">...</span>
    <a href="javascript:what">Hide span</a>
    <a href="javascript:what">Show span</a>
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  2.  

  3. #2
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Code:
    <script type="text/javascript">
    function hideIt() {
    document.getElementById('myspan').style.display='none'
    }
    function showIt() {
    document.getElementById('myspan').style.display=''
    }
    </script>
    <span id="myspan">poo poo poo poo</span><BR>
    <a href="javascript:hideIt()">Hide Span</a> 
    <a href="javascript:showIt()">Show Span</a>
    Tested: IE 6 | Moz 1.4
    - Brian

  4. #3
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Coolies, trying...
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  5. #4
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    here you go (untested, should work)...
    Code:
    <script type="text/javascript">
    function toggledisplay(state, spanid) {
    document.getElementById(spanid).style.display = state ;
    }
    </script>
    <span id="span1">Test Text</span><BR>
    <a href="java script:toggledisplay('none', 'span1')">Hide Span</a> 
    <a href="java script:toggledisplay('inline', 'span1')">Show Span</a>
    there is two ways of doing this...

    display or visibility

    visibility http://www.w3schools.com/css/pr_class_visibility.asp

    display
    http://www.w3schools.com/css/pr_class_display.asp
    JR

  6. #5
    JR
    JR is offline
    Senior Member JR's Avatar
    Join Date
    Nov 2002
    Location
    UK
    Posts
    4,354
    Member #
    257
    damn too late
    JR

  7. #6
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    How about iterating through every object of the page? I only know how to do it when they're form elements (document.formname.elements array).
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  8. #7
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    This script will change the state of an element or it's parent of a specified type to the state requested.
    Code:
    <script type="text/javascript">
    function changeState(element, type, state) {
        do {
            if (element && element.type == type) {
                document.getElementById(spanid).style.display = state ;
                return true;
            }
        while (element = element.offsetParent);
        return false;
    }
    </script>
    <span id="span1">Test Text</span><BR>
    <a href="java script:changeState(this, 'span', 'none')">Hide Span</a> 
    <a href="java script:changeState(this, 'span', 'inline')">Show Span</a>

  9. #8
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Rephrased: if an element's name matches via a regexp (which I already know) to a given string, hide it (for example); iterate for each element on the page.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  10. #9
    WDF Staff smoseley's Avatar
    Join Date
    Mar 2003
    Location
    Boston, MA
    Posts
    9,729
    Member #
    819
    Liked
    205 times
    This script will change the state of any elements meeting the criteria given. I left the comparison open.
    Code:
    <script type="text/javascript">
    function changeStateAll(matchString, displayState) {
        var elements = document.getElementsByTagName('*');
        for (var i=0; i<elements.length; i++) {
            if (element.id <comparison> matchString) {
                elements[i].style.display = displayState;
            }
        }
    }
    </script>
    <span id="span1">Test Text</span><BR>
    <a href="java script:changeState('span', 'none')">Hide Span</a> 
    <a href="java script:changeState('span', 'inline')">Show Span</a>

  11. #10
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Coolies, trying that now
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!


Page 1 of 2 1 2 LastLast

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:04 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com