Hello,
Some code likewould not retrive the style of a 'tr' in an html page.Code:document.getElementById('tr'+x).style
So what's the trick?
| SitePoint Sponsor |



Hello,
Some code likewould not retrive the style of a 'tr' in an html page.Code:document.getElementById('tr'+x).style
So what's the trick?
-1/2=999?
As far as I know it does, but only the explicitly set style.
Code html4strict:<div style="font-weight:bold"><div id="a">aaa</div></div> <script type="text/javascript"> var s=document.getElementById('a').style; document.write(s.fontWeight); //outputs nothing </script>Code html4strict:<div id="a" style="font-weight:bold">aaa</div> <script type="text/javascript"> var s=document.getElementById('a').style; document.write(s.fontWeight); //outputs 'bold' </script>
Saul



Thanks, helped out.
I actualy want it for this task. onclick of a link which is in "bold font style" changes it to normal font style or style="". I think what we did covers this part but I want to whenever I get back to that page without reloading it the style be in the normal format.
Hope I could say my words in a simple way. Please let me know if not.
Last edited by borna; Jun 12, 2007 at 02:44.
-1/2=999?



What is the best and simplest [to some extent] way to DHTML. I think reload without refresh is kind of dhtml.
Please let me know of some link and rich refrences.
-1/2=999?




You can always check if the style property is empty, then you know it must be bold:
Code javascript:var a = document.getElementById('foo'); toggleBold (a); function toggleBold (elm) { if (!elm.style.fontWeight || elm.style.fontWeight == '' || elm.style.fontWeight == 'bold') { // fontWeight is not set or font-weight is bold, toggle it: elm.style.fontWeight = 'normal'; } else elm.style.fontWeight = 'bold'; }
It's not the most flexible of functions, but it should do the trick in your case.
Bookmarks