Can anyone explain why my code does not work? I do not know exactly how many divs
will generate, but the maximum is 25.
So I wanted each click button to specifically open the div
"glue" attached to it.
In my thinking, I put a for
that goes by, naming the class --- if i
is 2 click_a2
will open cola2
and so on.
jQuery and HTML:
for (i = 0; i < 25; i++) {
$('.click_a'+i).click(function () {
$('.cola'+i).slideToggle();
});
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><buttonclass="click_a1"> Detalhes </button>
<div class="cola1" style="display:none" >
hey!
</div>
Note: I'll put a variable (instead of 1
) that will add up everything this code rolls.