Good people, I have a problem here. I searched several times here on the website and on the internet and did not have an answer that would help me enough, I still have questions.
I have a website and I have sectors "collapsible", so to illustrate, I would like to put an arrow pointing up and when I clicked, pointed down, or whatever. I managed to do this, however, only once, if I click again, the image stays down and does not change until the page refreshes. I put the image at the beginning of the text, just below I have an example.
In fact, what I really wanted was for it to change when I clicked on any part of the collapsible item title, but for now I only got it to change when I clicked on it.
Finally, there are two questions in this case. How do I get her to "loop" and every time I click she changes? and How do I get it to trigger when I click on the title too ??
I put the javascript code together to facilitate my tests, the idea is to move on to another file later. I'm a beginner, I have experience with HTML and CSS, but javascript is pretty basic, I'm reminiscing a lot of HTML and CSS with this project that I have not moved in a long time and would like a jauda. Thank you very much!
HTML with Javascript code together:
<div class="card">
<div class="card-header" role="tab" id="headingTwo">
<h5 class="mb-0">
<h1 class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo" ng-click="alert_step2()">
<img id="example" onclick="changeImage()" src="assets/img/arrow_up.png" width="20" height="25">
<script>
function changeImage(){
element=document.getElementById('example')
if (element.src.match("out")){
element.src="assets/img/arrow_up.png";
}
else{
element.src="assets/img/arrow_down.png";
}
changeImage.repeat(100);
}
</script>
Step 2 - Acknowledge Your Strengths (highest scores)
</h1>
</h5>
</div>
</div>
<div class="card">
<div class="card-header" role="tab" id="headingTwo">
<h5 class="mb-0">
<h1 class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo" ng-click="alert_step2()">
<h1 class="change"><img class="change img-change" src="assets/img/arrow_up.png" style="width: 20px; height: 25px">Step 2 - Acknowledge Your Strengths (highest scores)</h1>
Remembering that the script that Mateus Veloso gave me is underneath this collapse
Updated code:
<div class="card">
<div class="card-header" role="tab" id="headingTwo">
<h5 class="mb-0">
<script>
$('.change').click((e) => {
var img1 = 'assets/img/arrow_up.png';
var img2 = 'assets/img/arrow_down.png';
var element = $('.img-change');
if(element.attr('src') === img1){
element.attr('src',img2);
}else if(element.attr('src') === img2){
element.attr('src',img1);
}
});
</script>
<h1 class="collapsed change" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo" ng-click="alert_step2()"> <img class="change img-change" src="assets/img/arrow_up.png" style="width: 20px; height: 25px">Step 2 - Acknowledge Your Strengths (highest scores)</h1>
</h1>
</h5>
</div>