0

I have a question regarding the IE7

I want to make every column of my table has the same width no matter what contents they have

 $("table").each(function(){
        var column =0;

        var totalWidth = $(this).width();
        $('tr:nth-child(1) td',this).each(function(){
            column ++;
        })

        var cellWidth = totalWidth / column;
        $('td', this).css('width', cellWidth);
    })

My codes work perfect on chrome and FF but not IE 7. I am not sure why. Can anyone help me about it? Thanks a lot!

6
  • 2
    Did you specify UNITS px? em? watermelons per second? Commented Aug 23, 2013 at 17:10
  • What version of jquery are you using? jquery 2.x supports IE9+. jquery.com/browser-support Commented Aug 23, 2013 at 17:10
  • 2
    @Diodeus watermelons per second? I think you meant to say Gallaghers :) Commented Aug 23, 2013 at 17:14
  • @Diodeus I tried cellWidth +'px' but it is still not working. Commented Aug 23, 2013 at 17:16
  • you can just do var column = $('tr:first td',this).length; instead of looping and manually counting the columns Commented Aug 23, 2013 at 17:30

3 Answers 3

2

nth-child is CSS3 selector and does not supported by IE 7. Try something else.

Sign up to request clarification or add additional context in comments.

3 Comments

is :first supported in IE7? This was the track I was going down, too. +1
nth-child is supported as a jQuery selector though and will work in IE7 right?
Richard, yes, IE7 can work with ":first", but only if web-page has declarated doctype.
1

Why don't you just put a class on all of your columns and then set it in CSS? That is just a waste of jQuery code.

<td class="col">...</td>

Then...

.col {
    width: 50px;
}

Or if you need it to be a certain percent of the page/table...

.col {
    width: 20%;   /* if 5 columns in the table, make each 20% of table width */
}

1 Comment

The problem is I have dynamic data and I don't know how many cell and what kind of contents I have.
1

Set the table's table-layout to

table-layout:fixed;

and provide a width shouldn't need jquery then

1 Comment

The problem is I have dynamic data and I don't know how many cell and what kind of contents I have.

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.