February 9th, 2010


How to align vertically an element with JavaScript

by Dragos, on December 24th, 2008  

If you would like to align an element vertically within a parent element, i use the following script.

<script type=”text/javascript”>

if (typeof window.innerWidth != ‘undefined’)
{
bh = window.innerHeight
}
if (typeof document.getElementById(“myElementID”).offsetHeight != ‘undefined’)
{
mbh = document.getElementById(“myElementID”).offsetHeight
}

document.getElementById(“myElementID”).style.marginTop=Math.round((bh-mbh)/2)+’px’);

</script>

This will arrange an element in the middle of a webpage.

How to apply change to all TDs within a TR (columns withing a row)

by Dragos, on October 5th, 2008  

I wanted to change the background color for a row with document.getElementById(row_id).style.backgroundColor=’red’ but unfortunately that doesnt work for some reason. Then i thought this could be done by applying the same style to all of the columns within a row (all TDs withing a TR). I’ve searched the web for such a function but i [...]