How do I change the column width in a table using JavaScript?
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="S开发者_StackOverflowwitch 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?
Try using document.getElementById().width instead of .style.width
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.
精彩评论