Hello World
Hello World

Reputation: 371

Is there a way to invert all colors on the page with a button click, using jQuery and/or CSS?

I'm hoping to invert all the colors on the page on a button click, and I haven't learned to invert colors. Is there some way to achieve this with a jQuery or JS method, e.g:

$("#button").click(function() {
  $(body).invert()
}

or do I have to go through the CSS method?

Thanks.

Upvotes: 1

Views: 1070

Answers (1)

Deykun
Deykun

Reputation: 1271

Yes, you can do it with CSS:

body.invert {
  filter: invert(1);
}

https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/invert

Just toggle class .invert with JS click.

Upvotes: 3

Related Questions