11

I need to vary a table's width after a click event in jQuery.

HTML:

<table class="zebra" border=0>

Case 1:

$("table.zebra").css("width","600px");

Case 2:

$("table.zebra").css("width","200px");

CSS:

table.zebra{}
table.zebra tr.even td, table.zebra tr.even th { background-color:#FDD017; }
table.zebra tr.odd td { background-color:#FFF380; }

This does not change the table's width like I want.

What am I doing wrong?

4 Answers 4

14

This should do the trick.

<table class="zebra">
  <tr>
    <td>foo</td>
    <td>bar</td>
  </tr>
</table>

<script type="text/javascript">
  $(function() {
    $('table.zebra').attr('width', 500);
  });
</script>
Sign up to request clarification or add additional context in comments.

Comments

10

Try this:

$("table.zebra").width(200);

Reference: http://docs.jquery.com/CSS/width#val

3 Comments

still I not able to get Resize the Table width?
the width() will get the current computed width of the first matched element, according to is.gd/9VR3. Not a setter, I think.
@Sepehr, there is a setter as well .width(val)
5

This should do the trick

$("table.zebra").width('200px');

Comments

0

This worked for me

    $('#MyModalID').find('.modal-dialog').css({
                width: '800px'
            });        

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.