SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help with javascript cookie

    I have javascript tree which is built and defined with list items

    The ul's gets the style property display= none when uncollapsed and no style when collapse. The idea is to remember the state of the tree. I want to do this by saving the style properties in a cookie. I got most of the cookie script working only i can't seem to get the style properties and store them.

    anyone help please, much appreciated

    Here is the start of the javascript

    HTML Code:
    var stateColl= document.getElementsByTagName("ul");
    		for( i=0; i < stateColl.length;i++)
    			{
    				alert(stateColl[i]);
    		}
    and this how mu html looks like ;
    for collapsed tree;
    HTML Code:
    <ul>
      <li></li>
    <li></li>
    <li></li>
    <li></li>
    </ul>
    for uncollapsed tree
    HTML Code:
    <ul style="overflow: visible; display: none;">
      li></li>
    <li></li>
    <li></li>
    <li></li>
    <ul>

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    The style property is what you use to access style attributes.

    For example, if el is the element:

    el.style.overflow
    or
    el.style.display
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have tried this
    var stateColl= document.getElementsByTagName("ul").getAttribute("display");

    but doesn't seem to be supported by browser

    any suggestion ??

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    getElementsByTagName("ul") gives you an array-like collection.
    You need to provide an array index (such as [0]) to reference only one single element.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Zealot
    Join Date
    May 2005
    Posts
    117
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried this;
    var stateColl= document.getElementsByTagName("ul");
    for( i=0; i < stateColl.length;i++)
    {
    var atributes= stateColl[i].getAttribute("display");

    alert(atributes+"<br>");


    }
    but seem to get null as a result... but did find the amount of ul's

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2007
    Location
    Oskarshamn, Sweden
    Posts
    82
    Mentioned
    0 Post(s)
    Tagged
    1 Thread(s)
    display is not an attribute for the ul. Use the style property, like Paul wrote above.
    Code:
    stateColl[i].style.display


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
  •