[Javascript] Accessing property values using getElementById
Troy III Ajnej
trojani2000 at hotmail.com
Wed Nov 23 18:18:03 CST 2011
That's because javascript is unaware of
the style properties set by CSS.
Only style properties set by javascript
are available/known to javascript style
keyword.Anyway style is supplied by DOM.
You need a key for current-style.
And since i have it in my private javascript library here is
a cross-browser and fully backward-compatible version method
which can be used independently.
---------------------8<-------------------------------------
cS=
/*b.b. Troy III p.a.e.*/
function cS(x){return getComputedStyle(x,0)||x.currentStyle}
--------------------------------->8-------------------------
usage:
---------------------8<-------------------------------------
cS(myDiv).width;
--------------------------------->8-------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Troy III
progressive art enterprise
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----------------------------------------
> Date: Wed, 23 Nov 2011 17:17:22 -0500
> From: web.listserv at gmail.com
> To: Javascript at lists.evolt.org
> Subject: [Javascript] Accessing property values using getElementById
>
> Greetings,
>
> I have been experimenting with getElementById method to access individual
> elements property values.
>
> For example, in my test web page, I have <h1 id="id_h101"> tag's font-size
> property set to 16px and <table id="id_tbl01"> tag's border-width set to
> 2px. Both via my CSS sheet in the <head> section.
>
> However, when using a for - in loop to step through the respective style
> object (document.getElementById('id_h101').style and
> document.getElementById('id_tbl01').style), some properties are displayed
> with default values of false or 0 but no values appeared for the <h1
> id="id_h101"> tag's fontSize property or the <table id="id_tbl01"> tag's
> borderWidth property or any other properties without a preset default value.
>
> Although the values I set did take effect on my web page but why can't
> getElementById('tagID').style show me the expected results?
>
> Your advice and suggestions are greatly appreciated.
>
> George
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
More information about the Javascript
mailing list