Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

188
Views
I am trying to make all classes (sometags) turn pink once I call it in javascript it has to be onClickEvent

I am trying to make all classes called (sometags) turn pink once I have an onClickEvent in javascript.

  1. sometags has to be stored in css
  2. has to be on click event.

Thank you in advance for the help.

function tag() {
  //document.getElementById("tag").onclick = someTags;
  document.getElementById("demo").style.color = "pink";

}
<style>.someTags {
  color: pink;
}

</style>
<h2 class="someTags">QUESTIONS:</h2>

<ol>
  <li id="questionOne" onMouseOver="mouseOverQ1()" onMouseOut="mouseOutQ1()">When 'mouseover' occurs on this question text, the font should become Courier.</li>
  <li id="questionTwo">When this text is double-clicked, a red double border 10px wide should appear. When double-clicked again, the border should disappear. (HINT: use rgb(x, y, z) for colours, not words.) Repeated double-clicks toggle between red border and no border.</li>
  <li id="questionThree" onclick="changeColor()">When this text is clicked the text should have a blue color. If clicked again, it should go green. Repeated clicks toggle the colour between blue and green.</li>
  <li id="questionFour" onMouseOut="mouseOutQ4()">When 'mouseout' occurs on this text, question 6 should have the text "Nothing to be done here" displayed.</li>
  <li id="q5" onclick="questionFive('chartreuse');" class="someTags">When this text is clicked, the background colour of the webpage becomes 'chartreuse'.</li>

  <li id="changeQ4" class="question6" class="someTags">Mouseover here will make the text disappear.</li>

  <li id="demo" class="someTags">When this text is clicked, change the background colour to pink of the first and third tags whose css class="someTags".</li>
</ol>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try This

function pink() {
    elements = document.getElementsByClassName('someTags');
    for (var i = 0; i < elements.length; i++) {
        elements[i].style.backgroundColor="pink";
    }
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta
      name="viewport"
      content="width=
    , initial-scale=1.0"
    />
    <title>Document</title>
  </head>
  <body>
    <h2 class="someTags">QUESTIONS:</h2>

    <ol>
      <li
        id="questionOne"
      >
        When 'mouseover' occurs on this question text, the font should become
        Courier.
      </li>
      <li id="questionTwo">
        When this text is double-clicked, a red double border 10px wide should
        appear. When double-clicked again, the border should disappear. (HINT:
        use rgb(x, y, z) for colours, not words.) Repeated double-clicks toggle
        between red border and no border.
      </li>
      <li id="questionThree">
        When this text is clicked the text should have a blue color. If clicked
        again, it should go green. Repeated clicks toggle the colour between
        blue and green.
      </li>
      <li id="questionFour">
        When 'mouseout' occurs on this text, question 6 should have the text
        "Nothing to be done here" displayed.
      </li>
      <li id="q5" class="someTags">
        When this text is clicked, the background colour of the webpage becomes
        'chartreuse'.
      </li>

      <li id="changeQ4" class="question6" class="someTags">
        Mouseover here will make the text disappear.
      </li>

      <li id="demo" class="someTags">
        When this text is clicked, change the background colour to pink of the
        first and third tags whose css class="someTags".
      </li>
    </ol>

    <button onclick="pink()" class="someTags">Pink</button>

    <script src="app.js"></script>
  </body>
</html>

about 4 years ago · Juan Pablo Isaza Report

0

Here isa solution that i think can help.

 const classElements = document.querySelectorAll(".someTags");
    const btnDemo = document.getElementById("demo");
    btnDemo.addEventListener('click', () =>
    {
      classElements.forEach(element => element.classList.add("green"));
    });
    .green {
      background-color: pink;
    }
<h2 class="someTags">QUESTIONS:</h2>

  <ol>
    <li id="questionOne" onMouseOver="" onMouseOut="">When 'mouseover' occurs on this question text, the font should become Courier.</li>
    <li id="questionTwo">When this text is double-clicked, a red double border 10px wide should appear. When double-clicked again, the border should disappear. (HINT: use rgb(x, y, z) for colours, not words.) Repeated double-clicks toggle between red border and no border.</li>
    <li id="questionThree" onclick="changeColor()">When this text is clicked the text should have a blue color. If clicked again, it should go green. Repeated clicks toggle the colour between blue and green.</li>
    <li id="questionFour" onMouseOut="">When 'mouseout' occurs on this text, question 6 should have the text "Nothing to be done here" displayed.</li>
    <li id="q5" onclick="questionFive('chartreuse');" class="someTags">When this text is clicked, the background colour of the webpage becomes 'chartreuse'.</li>

    <li id="changeQ4" class="question6" class="someTags">Mouseover here will make the text disappear.</li>

    <button id="demo" class="someTags">Button to click.</button>
  </ol>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!