JScript Method Problem

Discussion in 'OT Technology' started by doggfather, Apr 8, 2006.

  1. doggfather

    doggfather New Member

    Joined:
    Aug 6, 2005
    Messages:
    224
    Likes Received:
    0
    <script>
    function displayFullNews(ID) {
    if (ID.style.display=='list-item') { ID.style.display = 'none';}
    else {ID.style.display = 'list-item';}
    }
    </script>
    <style>
    #art1 {display:none}
    #art2 {display:none}
    </style>
    <ul>
    <li style="display:list-item" onclick="javascript:displayFullNews('art1')">Article I
    <ul>
    <li id="art1">This is article I
    </ul>
    <li style="display:list-item" onclick="javascript:displayFullNews('art2')">Article II
    <ul>
    <li id="art2">This is article II
    </ul>
    </ul>

    -------------
    function displayFullNews(ID) {
    if (ID.style.display=='list-item') { ID.style.display = 'none';}
    else {ID.style.display = 'list-item';}
    }


    Hwo come when I replace the ID in the if else with art1 (the style ID), it works but it doesn't work when I use ID?

    Could someone help me? I don't want to have to hard code, I want to keep it as a method
     
  2. Nocera

    Nocera ...

    Joined:
    Aug 9, 2000
    Messages:
    1,307
    Likes Received:
    0
    Location:
    Long Island, NY
    Code:
    <script>
         function displayFullNews(ID) {
              var idel = document.getElementById(ID);
              if (idel.style.display=='list-item') { 
                   idel.style.display = 'none';
              }
              else {
                   idel.style.display = 'list-item';
              }
         }
    </script>
    
     
  3. doggfather

    doggfather New Member

    Joined:
    Aug 6, 2005
    Messages:
    224
    Likes Received:
    0
    thanks!
     

Share This Page