0

how to change all body elements' color with a single click in javascript. like;

a.url{
color:#000;
}
div.sample{
color:#000;
}
table td.sample{
color:#000;
}

can i change all color properties of elements to #CCCCCC for example?

I think i have to clear my question. I don't want to change all elements color to target value, i want to change lets say; all blue colors to black. just blue colors, not all of them.

Recep Şimşek
  • 569
  • 7
  • 16

3 Answers3

3

you can use:

html:

<button id="changeColor">Change Color</button>

and javascript:

$('#changeColor').on('click', function(){
    $('*').css('color', '#CCCCCC');
}
Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
0

With jQuery:

$element.click(function() {
  $('body *').css('color', '#ccc !important');
});
elclanrs
  • 92,861
  • 21
  • 134
  • 171
0

See this answer for how to add a stylesheet rule: How do you add CSS with Javascript?

Add the rule

* {
  color: #CCC !important;
}

or possibly:

body * {
  color: #CCC !important;
}
Community
  • 1
  • 1
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74