Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 843 | Replies: 2
![]() |
No, as far as I know, you can't do that. But you can surely get hold of all the elements which use that class and change their property which is what you must be aiming for, methinks.
<html>
<head>
<style>
.one
{
background-color: blue;
}
.two
{
background-color: green;
}
</style>
<script>
getElementsByClassName = function (needle)
{
var my_array = document.getElementsByTagName("*");
var retvalue = new Array();
var i;
var j;
for (i = 0, j = 0; i < my_array.length; i++)
{
var c = " " + my_array[i].className + " ";
if (c.indexOf(" " + needle + " ") != -1)
retvalue[j++] = my_array[i];
}
return retvalue;
}
function changeColor(name, color)
{
var elements = getElementsByClassName(name);
for(var i = 0; i < elements.length; ++i)
{
if(elements[i])
elements[i].style.backgroundColor = color;
}
}
</script>
</head>
<body>
<form>
<p class="one">Hello to all</p>
<p class="two">Someone is here</p>
<p class="one">Really? Who is he?</p>
<p class="two">Do I know him?</p>
<input type="button" value="Blue to Red" onclick="changeColor('one', 'red');" />
<input type="button" value="Green to Yellow" onclick="changeColor('two', 'yellow');" />
</form>
</body>
</html> Last edited by ~s.o.s~ : Jul 24th, 2007 at 1:25 pm.
I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
•
•
Join Date: Jul 2007
Posts: 8
Reputation:
Rep Power: 0
Solved Threads: 2
Yes, it is not possible to modify rules in the CSS file, but you can modify the style of the DOM node.
voynex.com - high quality software and web development.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)






Linear Mode