Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

64
Vistas
How to change text color when I click and change the other color of text

I don't have any Js as I am a beginner. I want when I click on a text it changes the color but when click other text change color and also return the previous text to the same color.

<div class="mt-5 first-member" onclick="document.getElementById('myImage').src='./assets/images/person-team.png'">
  <span>
                        <small>
                        <sup>01</sup>
                     </small>
                  </span>
  <h1> Alexandr Bruegel</h1>
</div>
<div class="mt-3 other-member" onclick="document.getElementById('myImage').src='./assets/images/bg-img.png'">
  <span>
                        <small>
                        <sup>02</sup>
                     </small>
                  </span>
  <h1>Ann Fowler</h1>
</div>

7 months ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This code should work for you:)

document.querySelector('.mt-5').addEventListener('click',function(){
//document.getElementById('myImage').src='./assets/images/person-team.png'
document.getElementById('text1').style.color = 'red'
document.getElementById('text2').style.color = 'black'
})
document.querySelector('.mt-3').addEventListener('click',function(){
//document.getElementById('myImage').src='./assets/images/bg-img.png'
document.getElementById('text2').style.color = 'red'
document.getElementById('text1').style.color = 'black'
})
<div class="mt-5 first-member" >
  <span>
                        <small>
                        <sup>01</sup>
                     </small>
                  </span>
  <h1 id='text1'> Alexandr Bruegel</h1>
</div>
<div class="mt-3 other-member" >
  <span>
                        <small>
                        <sup>02</sup>
                     </small>
                  </span>
  <h1 id='text2'>Ann Fowler</h1>
</div>

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos