O
O
Oleg Parfenyuk2018-02-14 17:39:55
JavaScript
Oleg Parfenyuk, 2018-02-14 17:39:55

How can I change the background of a block when clicking on a link?

How can I make it so that when clicking on a link, the block in which this link is located is painted over in the same color?

<div class="wrapper">
  <div class="container">
    <div class="sub-container">
      <ul>
        <li><a href="#" data-color="red" class="red"></a></li>
        <li><a href="#" data-color="green" class="green"></a></li>
        <li><a href="#" data-color="blue" class="blue"></a></li>
      </ul>
    </div>
  </div>
  <div class="container">
    <div class="sub-container">
      <ul>
        <li><a href="#" data-color="red" class="red"></a></li>
        <li><a href="#" data-color="green" class="green"></a></li>
        <li><a href="#" data-color="blue" class="blue"></a></li>
      </ul>
    </div>
  </div>
  <div class="container">
    <div class="sub-container">
      <ul>
        <li><a href="#" data-color="red" class="red"></a></li>
        <li><a href="#" data-color="green" class="green"></a></li>
        <li><a href="#" data-color="blue" class="blue"></a></li>
      </ul>
    </div>
  </div>
</div>

.wrapper{
  display: flex;
  flex-direction: row;
  padding: 20px;
  background-color: black;
}

.container {
  flex: 1;
  padding: 10px;
  transition: all 2s;
}

.sub-container {
  padding: 10px;
}

.sub-container ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  height: 300px;
  align-items: flex-end;
}

.sub-container ul li {
  flex: 1;
  margin: 10px;
  border: 3px solid #fff;
  padding: 10px;
  height: 60px;
}

.sub-container ul li a{
  display: block;
  width: 100%;
  height: 100%;
}

a.red {background-color: red}
a.green {background-color: green}
a.blue {background-color: blue}


5a844a221c27f649825919.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stimulate, 2018-02-14
@id_oleg_parfenyuk

https://jsfiddle.net/ba10hy1w/2/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question