Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
Estoy tratando de hacer que todas las clases (algunas etiquetas) se vuelvan rosas una vez que lo llamo en javascript, tiene que estar en ClickEvent

Estoy tratando de hacer que todas las clases llamadas (algunas etiquetas) se vuelvan rosadas una vez que tengo un onClickEvent en javascript.

  1. sometags tiene que ser almacenado en css
  2. tiene que estar en el evento de clic.

Gracias por adelantado por la ayuda.

 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 Respostas
Responde à pergunta

0

Prueba esto

 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 Relatório

0

Aquí hay una solución que creo que puede ayudar.

 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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda