[Javascript] Accessing property values using getElementById

David Hucklesby hucklesby at gmail.com
Wed Nov 23 21:18:22 CST 2011


On 11/23/11 2:17 PM, George Tsang wrote:
> Greetings,
>
> I have been experimenting with getElementById method to access individual
> elements property values.
>

Instead of testing the style attribute, which you appear to be doing, try:

var oElement = document.getElementById('id_tbl01'); // for example

if (oElement.currentStyle && !window.opera) {
// for Internet Explorer
return oElement.currentStyle['borderWidth'];
} else if (window,getComputedStyle) {
// For real browsers:
window.getComputedStyle(oElement, '').getPropertyValue('border-width');
}

Note the camel case property name for IE. Also be prepared for IE to
give less than useful results in some cases. :(

HTH.
-- 
Cordially,
David


More information about the Javascript mailing list