I am completely new to Javascript; please could someone assist me with my question in the simplest way possible for me to understand.
You can do this with CSS or Javascript. Either way, the result is the same.
You can do this by wrapping the paragraphs in a <div>
, and then making a CSS :hover
selector.
.paragraphs:hover {
color: lightgreen;
}
<div class="paragraphs">
<p>One</p>
<p>Two</p>
<p>Three</p>
</div>
Wrap all the paragraphs in a <div>
, then add an mouseenter
and mouseleave
event listener.
var paragraphs = document.querySelector('.paragraphs');
paragraphs.addEventListener('mouseenter', e => {
paragraphs.style.color = 'lightgreen';
});
paragraphs.addEventListener('mouseleave', e => {
paragraphs.style.color = 'black';
});
<div class="paragraphs">
<p>One</p>
<p>Two</p>
<p>Three</p>
</div>