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.
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";
});
}
You can just do document.querySelectorAll(".RockToScissors, .RockToLizard");
to target both elements.
document.querySelectorAll()
supports all CSS selectors, and ,
is also valid.
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 ...
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 = ...
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 ...