1

I'm trying to switch the width of two columns in a table when a user clicks on an image. I'm using a JavaScript on click even and if I put the new column width as % it works but it doesn't seem to work using px or em which is wht I want use to have better control over the columns. This is the code I'm using:

<img alt="Change Widths" title="Switch column widths" src="/*images_path*/*image*.png" onclick="for (j=1;j<=200;j++){document.getElementById('cola'+j).style.width = '60%'; document.getElementById('colb'+j).style.width = '28%';}" onmouseover="this.style.cursor='pointer';"/>

I'm using Firefox is that makes a difference. Can anyone help me?

1
  • If you're trying to decrease the size of the cells, you may run into trouble if you're trying to decrease it to a size less than the width of the contained text. I'd suggest setting overflow: hidden and white-space: nowrap on your cells. Note, however, that this will end up hiding content that overflows the cell. Commented Feb 18, 2011 at 14:00

2 Answers 2

0

Try using document.getElementById().width instead of .style.width

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

Comments

0

It's worked for me selecting an ID on the TD of the table to change and setting .width to a px value. I never used .style.width, just .width.

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.