Change css class when hovering html element

Sten Stmith

I have a loop of divs with a class item. When mouseover on an element, active-item class is added via javascript:

<div class="item"></div>
<div class="item"></div>
<div class="item"></div>

<!--on mouseover-->
<div class="item active-item"></div>
<div class="item"></div>
<div class="item"></div>

When item active-item class appears, I want to add opacity: 0 to item class, and to add opacity :1 to item active-item. I need to do it without :hover, because that its expand card and when mouse will leave item, it will be opacity:0.

Fabrizio Calderan

No need to use JS for this task

.itemcontainer:hover .item:not(:hover) {
  opacity: 0
}
<div class="itemcontainer">
  <div class="item">1
  </div>
  <div class="item">2
  </div>
  <div class="item">3
  </div>
</div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Change CSS of li class when hovering over a class

How to change CSS elements of an element when hovering on another

How to change css of one class when hovering over another?

Displaying an HTML element when hovering over only with CSS

Change background of the parent when hovering a child element

css transition - issue when hovering on the element

Change class name of header when hovering

How to change css of img when hovering parent

Change animation's transition speed in CSS when un-hovering element

HTML/CSS tooltip that should appear when hovering over a certain element does not appear

Zoom in when hovering over image - CSS & HTML

How to change color of element when hovering over another element?

Change image properties on hover when hovering element which trigger when hovering the image

How to change color on every element in div when hovering?

How to change opacity of child-element when hovering his parent

Change image to black and white when hovering a another element inside it

How to trigger two hovers when hovering over single element CSS

Trigger CSS animation when hovering over pseudo element?

Changing CSS of one element when it's hovering another

Change class of other div when hovering on one div

Change HTML element class name based on media query / when printing

CSS change color of span when hovering over button

How do You Change Content in CSS When Hovering?

HTML element moving when viewport width changes, but no change in CSS

Is there a way to change the appeareance of an html text when hovering on the div that contains it?

Change li element class when pressing a button and in that css class change background color

HTML/CSS/JQUERY - Dropdown disappear when not hovering on menu

how to change the visibility/opacity of another html element by hovering over another html element using jquery?

How to change text-decoration to underline when hovering the a element, if the a element is below another element with position absolute?

TOP Ranking

HotTag

Archive