Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2006
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Width attribute not taking effect

    I am using javascript to create a table-ish layout, I am using the following function to resize the 'cells' within a 'row'. It is layed out such that there is an 'insert cell' at each end to drop new 'cells' into as well as an 'insert cell' between each 'data cell'. Each 'insert cell' is only 1.25% wide and the function should resize the 'data cells' evenly; it does change the width attribute when viewed with firefox's DOM inspector but doesn't actually render as a different width.

    Here is the function:

    function resizeCells(row){
    var datacells=(row.childNodes.length-1)/2;
    var insertcells=datacells+1;
    var insertcellstotal=insertcells*1.25;
    var datacellstotal=100-insertcellstotal;
    var datacellwidth=datacellstotal/datacells;
    var cells=row.childNodes;
    for(var cell=1 ; cell < cells.length ; cell+=2 ){
    cells[cell].setAttribute('width',datacellwidth + '%');

    }
    }



    edit:All the 'cells' are declared as float:left
    Last edited by madsporkmurdere; 05-07-2006 at 11:35 PM.

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Change
    Code:
    cells[cell].setAttribute('width',datacellwidth + '%');
    to
    Code:
    cells[cell].style.width = datacellwidth + '%';
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •