0

I have HTML table as shown below. It has seven columns. I am adjusting the table cell width using jQuery. The total percentage is 100 in the jQuery. However, the table is not taking the complete space; there is some unused space. How to correct this?

http://jsfiddle.net/Lijo/eFS5J/3/

enter image description here

 $(document).ready(function () {


        $('#gridDiv').css('width', '630px');


        //Set width of table cells
        var numberOfColumns = 7;
        $('.resultGridTable th, .resultGridTable td').each(function (i) {


            $(this).css('background-color', (['Purple', 'Orange', 'Purple', 'Orange', 'Purple', 'Orange', 'Purple'][i % 7]));

            if (i % numberOfColumns == 0) {
                $(this).css('width', '15%');
            }

            if (i % numberOfColumns == 1) {
                $(this).css('width', '15%');
            }

            if (i % numberOfColumns == 2) {
                $(this).css('width', '15%');
            }

            if (i % numberOfColumns == 3) {
                $(this).css('width', '15%');
            }
            if (i % numberOfColumns == 4) {
                $(this).css('width', '10%');
            }
            if (i % numberOfColumns == 5) {
                $(this).css('width', '15%');
            }

            if (i % numberOfColumns == 6) {
                $(this).css('width', '15%');
            }


        }
 );


    }
);
2
  • is there a reason why you want to do that in jquery and not css? Commented Jun 12, 2012 at 9:33
  • 1
    The problem is probably because the table itself has to be width:100% Commented Jun 12, 2012 at 9:34

3 Answers 3

3

Add the following attribute to your table element.

width="100%"
Sign up to request clarification or add additional context in comments.

Comments

0

Here you go:

<table class="resultGridTable" cellspacing="0" id="detailContentPlaceholder_grdTaxAssociates" style="border-collapse: collapse; width:100%;">

Comments

0

Only set width as 100% by using inline css in below place

<table class="resultGridTable" cellspacing="0" id="detailContentPlaceholder_grdTaxAssociates"
                    style="border-collapse: collapse;width:100%;">

See demo here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.