JavaScript How to change css of one class when hovering over another? change class when clicked,change class when scroll,change class

I am new to css especially combinators but I am trying to change css of a p element when hovering over a h1 element both of which are in a div of class "a" but I can't figure out how to do it.Here is my code

HTML

<div class="a">
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</div>

CSS

div.a h1:hover ~ div.a p {color:red;}

So what am I doing wrong?

Answer:1

You don't need to target the div element again.

All Paragraphs JsFiddle Demo

First Paragraph Jsfiddle Demo

div.a h1:hover~p{color:red;}
<div class="a">
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<p>This is a paragraph.</p>
</div>
<p>Some other text.</p>
Answer:2

This solution should work :

div.a > h1:hover + p {
    color:red;
}

> h1:hover to select h1:hover element where the parent is div with class 'a'

+ p to select p element that are placed immediately after h1:hover element

Answer:3

new Date(Infinity) is too far, and so is new Date(Number.MAX_SAFE_INTEGER - 1). I need this so I can run astronomical simulations on a Node cluster. JK, I'm just messing around, and SO imposed a ...

new Date(Infinity) is too far, and so is new Date(Number.MAX_SAFE_INTEGER - 1). I need this so I can run astronomical simulations on a Node cluster. JK, I'm just messing around, and SO imposed a ...

I'm writing a lua script that I want to use with scrapy + splash for a website. I want to write a script that enters a text and then clicks on a button. I have the following code: function main(...

I'm writing a lua script that I want to use with scrapy + splash for a website. I want to write a script that enters a text and then clicks on a button. I have the following code: function main(...

app.js var bodyParser = require('koa-bodyparser'); app.use(bodyParser()); app.use(route.get('/objects/', objects.all)); objects.js module.exports.all = function * all(next) { this.body = yield ...

app.js var bodyParser = require('koa-bodyparser'); app.use(bodyParser()); app.use(route.get('/objects/', objects.all)); objects.js module.exports.all = function * all(next) { this.body = yield ...

  1. query string with multiple parameters
  2. query string with spaces
  3. query string with array
  4. query string with #
  5. query string with no value
  6. query string with ampersand
  7. query string with filter in elasticsearch
  8. query string with multiple parameters in c#
  9. query string with special characters
  10. query string with forward slash
  11. query string with parameters
  12. query string with hash
  13. query string with post
  14. query string with slash
  15. query string with spaces c#
  16. query string with plus sign
  17. query string with anchor tag
  18. query string with multiple parameters in javascript

I want to display products unit of measurement at the frontend. For that I have created weight_unit attribute in admin panel and I am adding it to products like gram, kilogram, liter, etc. But I can't ...

I want to display products unit of measurement at the frontend. For that I have created weight_unit attribute in admin panel and I am adding it to products like gram, kilogram, liter, etc. But I can't ...

  1. product display unit
  2. display unit product buy
  3. retail product display unit/shelves
  4. portable product display unit