Waffeloo wrote:
Hi,
I would like an event to trigger a change the style of all the elements that
belong to some CSS class.
I know it is possible to change the class of an element, for example with:
<script language=javascript>
function changeclass()
{document.getElementById(id).className="class_id"; }
</script>
<input type=checkbox onclick="javascript:changeclass()">
function changeclass(elem,newClass)
{document.getElementById(elem).className=newClass; }
</script>
<input type=checkbox onclick="javascript:changeclass('div_1','spec_9')" >
But this can only change one element. I would like to change the
"property:list" pairs of a CSS class, so that changes can apply to more
than one element.
Is it possible with javascript?
I think you can't modiy properties of a class defined
(except, perhaps with IE and sheetStyle.rules ?)
You can catch all tags collection of the page
and for each tag with a certain class, change it :
var D = document.getElementsByTagName('*');
for(var i=0;i<D.length;i++)
if(D[i].className=='truc') D[i].className="trick";
of course you need 2 classes
of course you need your elements have a class
(it is not always)
you may also search lists elements and change their styles
var L = document.getElementsByTagName('UL')
for(var i=0;i<L.length;i++)
if(L[i].style.textDecoration=='none') D[i].style.textDecoration='underline';
--
Stephane Moriaux et son [moins] vieux Mac