Style seems not to get my predefined values


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Style seems not to get my predefined values

  1. #1
    Konstantinos Guest

    Style seems not to get my predefined values


    Hello,
    I tried to define a style and use it like this:

    <style type="text/css">
    .tab{left: 17;}
    </style>

    <script language="JavaScript">
    function setState(tabNum){
    document.getElementById('tab'+tabNum).style.left = noPX(document.getElementById('tab'+tabNum).style.left)
    - 2;
    }

    //remove the "px" from the string and return an integer
    function noPX(strWithPX){
    return parseInt(strWithPX.substring(0, strWithPX.indexOf('px', 0)));
    }
    </script>

    <body>
    <div id="tab1" class="tab" onclick="setState(1);">
    General
    </div>
    </body>


    When I click on the div, the
    "document.getElementById('tab'+tabNum).style.left" statement
    is the empty string and not "17px" as it is supposed to be. (I have defined
    the value in the class definition.)

    Can anyone tell me why? Thanx in advance for even taking a look at it...

    Konstantinos


  2. #2
    ynwt Guest

    Re: Style seems not to get my predefined values


    You miss to specify the position properties to style sheet to know where it
    should be like

    .tab{position:absolute; left: 17;}
    OR
    .tab{position:relative; left: 17;}

    Hope this help,
    ynwt
    ====
    "Konstantinos" <ksykas@vizzavi.gr> wrote:
    >
    >Hello,
    >I tried to define a style and use it like this:
    >
    ><style type="text/css">
    > .tab{left: 17;}
    ></style>
    >
    ><script language="JavaScript">
    > function setState(tabNum){
    > document.getElementById('tab'+tabNum).style.left = noPX(document.getElementById('tab'+tabNum).style.left)
    >- 2;
    > }
    >
    > //remove the "px" from the string and return an integer
    > function noPX(strWithPX){
    > return parseInt(strWithPX.substring(0, strWithPX.indexOf('px', 0)));
    > }
    ></script>
    >
    ><body>
    > <div id="tab1" class="tab" onclick="setState(1);">
    > General
    > </div>
    ></body>
    >
    >
    >When I click on the div, the
    >"document.getElementById('tab'+tabNum).style.left" statement
    >is the empty string and not "17px" as it is supposed to be. (I have defined
    >the value in the class definition.)
    >
    >Can anyone tell me why? Thanx in advance for even taking a look at it...
    >
    >Konstantinos
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center