0

console.log($("#box4").css("background-color")); // Solution does not fit
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="box1" style="background-color: blue; opacity: 0.5;">
  <div id="box2" style="background-color: yellow; opacity: 0.5;">
    <div id="box3" style="bacground-color: green; opacity: 0.5;">
      <div id="box4" style="font-size: 30px; padding: 20px; opacity: 0.9;">Aloha</div>
    </div>
  </div>
</div>

Need to get background-color value for id="box4" with JS oder JQ. The real value of the color that the user sees in the browser must be found. Not a CSS value.

You need to either calculate the color change with an opacity value, or some other solution.

If I use the "COLOR PICKER" google chrome plugin, I get the value #a0b0c0, rgb(160, 176, 192).

It is enough if the speech will only work in google chrome.

Ilia Brykin
  • 271
  • 1
  • 8
  • Will asking for the `css` value work? `console.log ( $('#box4').css("opacity") ); console.log ( $('#box4').css("background-color") );` – Zak Feb 24 '22 at 17:13
  • And .. As `#box4` contains no `background` property .. It will return undefined or null ... Are you trying to get the background color of a div that's BEHIND `#box4` ? – Zak Feb 24 '22 at 17:14
  • The real value of the color that the user sees in the browser must be found. Not a CSS value. – Ilia Brykin Feb 24 '22 at 17:21
  • 1
    This is as close as you will get to what you are wanting to do .. https://pqina.nl/blog/use-the-javascript-eye-dropper-api-to-select-colors-on-the-web/ You may be able to create some JS to manipulate it by placing the cursor where you want and generating an artificial "click" .. – Zak Feb 24 '22 at 17:30
  • Now that's interesting, I'll give it a try. Thanks. – Ilia Brykin Feb 24 '22 at 17:32
  • There's a lot of discussion on algorithms here: https://stackoverflow.com/questions/726549/algorithm-for-additive-color-mixing-for-rgb-values but I cannot find a definitive statement of what would be used by any one system. Hope someone knows. – A Haworth Feb 24 '22 at 17:47

0 Answers0