How to set the cell width (HTML table) from Javascript code
Here's how you might do it with jQuery, a popular JavaScript library:
http://jsfiddle.net/VJTnN/2
$('td:nth-child(2)').css('width', '100px');
Using JavaScript to change table cells width
Something like this (for the first one:
document.getElementsByTagName('td')[0].style.width = '2px';
Or this for all:
var tds = document.getElementsByTagName('td');
for (var i = 0; i < tds.length; i++)
tds[i].style.width = '2px';
increase width and height of table cells
Instead of creating an html element, you're creating a textNode in the following code:
// Append a text node to the cell
var newText2 = document.createTextNode('<a href="">delete</a>' +'<a href="">show</a>');
newCell2.appendChild(newText2);
instead, you actually have to create html elements using createElement()
function as follows:
// Append a text node to the cell
var newText2 = document.createElement('a'); //create actual HTML element
newText2.innerHTML='show'; // set the elements properties
newText2.href="#";
newCell2.appendChild(newText2);
JSFiddle
this is just for demo purpose, you can actually create the remaining anchor and set all of their properties as shown above...
Update
As for changing the size, simply specify it in css as follows:
td{
width:250px;
height:250px;
}
JSFiddle
Update
You can set the height and width of dynamically created elements as follows:
newCell.style.width ='250px';
newCell.style.height ='250px';
For displaying an image, instead of creating an <a>
simply create <img>
and set it's source and do your logic on it's click event.
JSFiddle
Related Topics
Adding a Background Video with React
D3 Bar Chart Not Showing First Element in Array
Scrolling Log File (Tail -F) Animation Using JavaScript
Get Pixelcolor of CSS Background Image
Change the Fixed Navbar's Classes Depending on the Background of the Page Section It Hovers
Highlight Active Menu Item on Scroll
Change Image Onclick for a Set Amount of Time
Change the Color of a Text in Div Using Jquery Contains
Angular - Ngfor* Four Elements on Row
How to Replay a CSS3 Animation in Reactjs
CSS in My JavaScript Widget Colliding with Target Page CSS
Get Document.Stylesheets by Name Instead of Index
Where in the HTML File Should Jquery and Bootstrap Be Placed
Youtube API Not Working with iPad/Iphone/Non-Flash Device
Using Variables in Gulp for the Destination File Name
Screen Zooms in When a Bootstrap Modal Is Opened on iOS 9 Safari
Jquery .Position() Strangeness While Using CSS3 Rotate Attribute