1
I have two lists and wanted to make that by clicking first on the first list and then on the second, perform a function to make the two items green.
<p class="question"><span class="mark-question">1.</span> Relacione as fabricantes aos seus veículos</p>
<ul class="first-column">
<li data-answer="0,5">Ford</li>
<li data-answer="2">Fiat</li>
<li data-answer="3">Renault</li>
<li data-answer="">Ferrari</li>
<li data-answer="4" id="honda">Honda</li>
<li data-answer="1">Chevrolet</li>
</ul>
<ul class="second-column">
<li>Edge</li>
<li>Ônix</li>
<li>Palio</li>
<li>Sandero</li>
<li id="civic">Civic</li>
<li>Fusion</li>
<li>Fusquinha</li>
</ul>
Poxa valeu mano! But, how could I use the date to define when I should perform the function of changing the color or not? For example, I wanted you to change the color only when I first click on the "Honda" and then on the "Civic".
– Pedro Lucas Flor
@Pedrolucasflor in that case you can join
if (!clicked && !this.classList.contains('first-column')) return clicked = null;
before the firstif
in function.– Sergio
Thank you very much! But, one last question I copied your code to see how it worked and Chrome is telling me this message "Uncaught Typeerror: Cannot read Property 'addeventlistener' of null at main.js:5". I have had this problem with addeventlistener. I would like to know why?
– Pedro Lucas Flor
@Pedrolucasflor that means that the
document.querySelector
did not find the elements on the page and therefore one of the variablesfirst
orsecond
has no value.– Sergio
I managed to solve it! I was calling the script at head. This meant that "first-column" and "Second-column" did not exist
– Pedro Lucas Flor
@Pedrolucasflor boa!
– Sergio