JavaScript How to apply style to multiple classes on hover of an element? apply multiple style using jquery,apply multiple style in javascript,

Whenever I hover over #Rock div I want it to apply a style to both .RockToScissors & .RockToLizard at the same. A the moment I have:

<div onmouseover="overRock()" onmouseout="outRock()">
    <svg>
        <path stroke="#000" fill="#000"/>
    </svg>
</div>

Then in Javascript I have:

function overRock() {
    var myPara = document.querySelector(".RockToScissors");
    myPara.style.stroke = "#008000";
    myPara.style.fill = "#008000";
}

function outRock() {
    var myPara = document.querySelector(".RockToScissors");
    myPara.style.stroke = "#000";
    myPara.style.fill = "#000";
}

But this only allows me to apply the styling to one class. How can I make it apply to both .RockToScissors & .RockToLizard at the same time when hovering #Rock div?

I've tried var myPara = document.querySelectorAll(".RockToScissors, .RockToLizard"); but then the style doesn't apply to either.

Answer:1

Include both the class as part of the selector in querySelectorAll(). Then loop through them to set the style individually:

Try the following way:

function overRock() {
  var myPara = document.querySelectorAll(".RockToScissors, .RockToLizard");
  myPara.forEach(function(el){
    el.style.stroke = "#008000";
    el.style.fill = "#008000";
  });
}

function outRock() {
  var myPara = .querySelectorAll(".RockToScissors, .RockToLizard");
  myPara.forEach(function(el){
    el.style.stroke = "#000";
    el.style.fill = "#000";
  });

}
Answer:2

You can just do document.querySelectorAll(".RockToScissors, .RockToLizard"); to target both elements.

document.querySelectorAll() supports all CSS selectors, and , is also valid.

Answer:3

Hi i've tried to display an image on jsp but failing miserably. Im generating a chart and saving a the file than refreshing it, now i want to show this picture called chart on jsp. i know this is all ...

Hi i've tried to display an image on jsp but failing miserably. Im generating a chart and saving a the file than refreshing it, now i want to show this picture called chart on jsp. i know this is all ...

  1. amazon having trouble displaying orders
  2. we're having trouble displaying this page
  3. directv now having trouble displaying this video
  4. we're having trouble displaying this book
  5. we're having trouble displaying this video directv now
  6. we're having trouble displaying your passes
  7. we are having trouble displaying this page
  8. we are having trouble displaying this video
  9. we're having trouble displaying this page nokia lumia
  10. we're having trouble displaying all newsfeed updates

How to return a component through the JS innerHTML() function? With the code below, it is returning on the browser screen: [object Object] document.getElementById("threeline-icon").innerHTML = ...

How to return a component through the JS innerHTML() function? With the code below, it is returning on the browser screen: [object Object] document.getElementById("threeline-icon").innerHTML = ...

  1. reactjs return component
  2. react component return value
  3. reactjs function return component
  4. reactjs onclick return component
  5. reactjs return multiple components
  6. reactjs child component return

I am learning JavaScript and currently I build simple tip calculator using function and switch statement. Basically, tip 20% of the bill when the bill is less than $50, 15% when the bill is between $...

I am learning JavaScript and currently I build simple tip calculator using function and switch statement. Basically, tip 20% of the bill when the bill is less than $50, 15% when the bill is between $...

I have an array which looks like:- [[0,1], [0,2], [0,3], [1,1], [1,2]...] I am looking to remove one of the arrays from this array based on the indexOf() but I keep getting a value of -1, which ...

I have an array which looks like:- [[0,1], [0,2], [0,3], [1,1], [1,2]...] I am looking to remove one of the arrays from this array based on the indexOf() but I keep getting a value of -1, which ...

  1. remove array from array
  2. remove array from array python
  3. remove array from excel
  4. remove array from object javascript
  5. remove array from array php
  6. remove array from json object
  7. remove array from list python
  8. remove array from array java
  9. remove array from array swift
  10. remove array from another array python
  11. remove array from json object javascript
  12. remove array from multidimensional array php
  13. remove array from index javascript
  14. remove array from array typescript
  15. remove array from object
  16. remove array from array ruby
  17. remove array from array javascript lodash
  18. remove array from array numpy
  19. remove array from multidimensional array javascript
  20. remove array from object php