How to hide parts of a document, using Javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ronald Raygun

    How to hide parts of a document, using Javascript

    I have a document that is layed out in divs with ids and classes. There
    can be N divs of class "other" but only one div with id ="main". Only
    the div with id "main" should be visible.

    I want to be able to programatically select the visible portion of the
    document, by clicking a link at the bottom of the document. So for
    example, the links at the bottom of the page will show "Page1", "Page2" etc.

    Does anyone have an example that shows how I may do this?
  • Evertjan.

    #2
    Re: How to hide parts of a document, using Javascript

    Ronald Raygun wrote on 03 mei 2008 in comp.lang.javas cript:
    I have a document that is layed out in divs with ids and classes.
    There can be N divs of class "other" but only one div with id ="main".
    Only the div with id "main" should be visible.
    It is realy simple if you know JS and CSS.

    A class being a CSS attribute could also be an an attribute of your
    id='main' div, so let us forget about that first:

    =============== =======
    var temp = document.getEle mentsByTagName( 'div')
    for (var i=0;i<temp.leng th;i++)
    temp[i].style.display= 'none';
    document.getEle mentsById('main ').style.displa y='block';
    =============== ======

    [not tested]

    However, if you have other divs that should not be affected,
    and want to use the class 'other', do:

    =============== =======
    var temp = document.getEle mentsByTagName( 'div')
    for (var i=0;i<temp.leng th;i++)
    if (temp[i].className=='ot her')
    temp[i].style.display= 'none';
    document.getEle mentsById('main ').style.displa y='block';
    =============== ======
    >
    I want to be able to programatically select the visible portion of the
    Change your idea fron "visible" to "displayed" as the first in CSS slang
    means that the part will be displayed empty.
    document, by clicking a link at the bottom of the document. So for
    example, the links at the bottom of the page will show "Page1",
    "Page2" etc.
    >
    Does anyone have an example that shows how I may do this?
    I leave you to change this to the buttons on the bottom.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    • Ronald Raygun

      #3
      Re: How to hide parts of a document, using Javascript



      Evertjan. wrote:
      Ronald Raygun wrote on 03 mei 2008 in comp.lang.javas cript:
      >
      >
      >>I have a document that is layed out in divs with ids and classes.
      >>There can be N divs of class "other" but only one div with id ="main".
      >>Only the div with id "main" should be visible.
      >
      >
      It is realy simple if you know JS and CSS.
      >
      A class being a CSS attribute could also be an an attribute of your
      id='main' div, so let us forget about that first:
      >
      =============== =======
      var temp = document.getEle mentsByTagName( 'div')
      for (var i=0;i<temp.leng th;i++)
      temp[i].style.display= 'none';
      document.getEle mentsById('main ').style.displa y='block';
      =============== ======
      >
      [not tested]
      >
      However, if you have other divs that should not be affected,
      and want to use the class 'other', do:
      >
      =============== =======
      var temp = document.getEle mentsByTagName( 'div')
      for (var i=0;i<temp.leng th;i++)
      if (temp[i].className=='ot her')
      temp[i].style.display= 'none';
      document.getEle mentsById('main ').style.displa y='block';
      =============== ======
      >
      >
      >>I want to be able to programatically select the visible portion of the
      >
      >
      Change your idea fron "visible" to "displayed" as the first in CSS slang
      means that the part will be displayed empty.
      >
      >
      >>document, by clicking a link at the bottom of the document. So for
      >>example, the links at the bottom of the page will show "Page1",
      >>"Page2" etc.
      >>
      >>Does anyone have an example that shows how I may do this?
      >
      >
      I leave you to change this to the buttons on the bottom.
      >
      >
      Thanks very much. This provides me with a very good starting ground.

      Comment

      Working...