|
Prev: Getting a DIV to cover the whole HTML page, not just the browser screen?
Next: Getting a DIV to cover the whole HTML page, not just the browser screen?
From: Steve on 16 Apr 2008 14:10 Anyone have an example of getting and setting an attribute of a CSS class defined at the top of an HTML page? Thanks in advance
From: Jonathan N. Little on 16 Apr 2008 14:13 Steve wrote: > Anyone have an example of getting and setting an attribute of a CSS > class defined at the top of an HTML page? Do you mean via JavaScript? Or do you mean inserting a STYLE element within the HEAD? -- Take care, Jonathan ------------------- LITTLE WORKS STUDIO http://www.LittleWorksStudio.com
From: Steve on 16 Apr 2008 20:50 Jonathan N. Little wrote: > Steve wrote: > > Anyone have an example of getting and setting an attribute of a CSS > > class defined at the top of an HTML page? > > Do you mean via JavaScript? Or do you mean inserting a STYLE element > within the HEAD? Setting it up in the HEAD and then using javascript to alter it dynamically.
From: Jonathan N. Little on 16 Apr 2008 21:38 Steve wrote: > > Jonathan N. Little wrote: >> Steve wrote: >>> Anyone have an example of getting and setting an attribute of a CSS >>> class defined at the top of an HTML page? >> Do you mean via JavaScript? Or do you mean inserting a STYLE element >> within the HEAD? > > Setting it up in the HEAD and then using javascript to alter it > dynamically. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <meta http-equiv="content-language" content="en-us"> <title>template</title> <style type="text/css"> #theTarget { color: black; background-color: white; } </style> <script type="text/javascript"> function killTarget (){ var t=document.getElementById('theTarget'); t.style.color="red"; t.style.backgroundColor="#aaa"; } </script> </head> <body> <p><a href="#" onclick="killTarget()">Click Me</a> to shoot the <span id="theTarget"> target </span></p> </body> </html> -- Take care, Jonathan ------------------- LITTLE WORKS STUDIO http://www.LittleWorksStudio.com
From: Jeff on 17 Apr 2008 09:31
Jonathan N. Little wrote: > Steve wrote: >> >> Jonathan N. Little wrote: >>> Steve wrote: >>>> Anyone have an example of getting and setting an attribute of a CSS >>>> class defined at the top of an HTML page? >>> Do you mean via JavaScript? Or do you mean inserting a STYLE element >>> within the HEAD? >> >> Setting it up in the HEAD and then using javascript to alter it >> dynamically. The question is still nebulous. Jonathans "solution" will not change all elements of a particular class. If the OP wishes to do that he should look into addRule and insertRule, I don't remember which is IE and and which is everyone else. Those work with any selector, not just class names. I think the OP is unsure of what he wants. Jeff > > <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" > "http://www.w3.org/TR/html4/strict.dtd"> > <html> > <head> > <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> > <meta http-equiv="content-language" content="en-us"> > > <title>template</title> > > <style type="text/css"> > #theTarget { color: black; background-color: white; } > </style> > > <script type="text/javascript"> > function killTarget (){ > var t=document.getElementById('theTarget'); > t.style.color="red"; > t.style.backgroundColor="#aaa"; > } > > </script> > > </head> > <body> > <p><a href="#" onclick="killTarget()">Click Me</a> to shoot the <span > id="theTarget"> target </span></p> > </body> > </html> > > |