DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  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
    >



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
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links