1
In my project, I have some "Steps" to be followed and to advance the Steps, I put "Continue" Buttons at the end of each Steps, they expand the next Collapse and close the previous one, however, I also put arrows that change image (closed right, open down) when you click on them or the title and when I click on the move button, they don’t change, so some are down and some are to the right.
I would like them to go with Collapse, when closed, they turn to the right and when opened, they turn down, this only happens if I click them or the title, not the button.
Button code:
<div class="form-group row"><br/>
<button class="btn btn-primary" onclick="next(2)">
Continue <i class="fa fa-chevron-right"></i>
</button>
</div>
JS code of changing arrows:
$('h1.change').click(function (){
var img1 = 'assets/img/arrow_right.png';
var img2 = 'assets/img/arrow_down.png';
var index = $(this).attr('index');
var element = $('img[index='+index+']');
if(element.attr('src') === img1){
element.attr('src',img2);
}else if(element.attr('src') === img2){
element.attr('src',img1);
}
});
Collapses code:
<h1 index="1" class="collapsed change" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo"
aria-expanded="false" aria-controls="collapseTwo" ng-click="alert_step2()">
<img index="1" class="change img-change" src="assets/img/arrow_right.png" style="width: 20px; height: 25px">
Step 2 - Acknowledge Your Strengths (highest scores)
</h1>
I have no experience with javascript and am learning, these arrows are giving me a lot of trouble.
Changes in the Collapse:
if(step == 1)
{
$('#collapseOne').collapse('hide');
$('#collapseTwo').collapse('show');
$(".img-change").attr("src", "assets/img/arrow_right.png");
$("[data-toggle=collapse]").each(function(){
$(this).attr("aria-expanded", "false").addClass("collapsed");
$($(this).attr("href")).removeClass("show");
});
}
End of the js code
else if(step == 11)
{
$('#collapseTen').collapse('hide');
$('#collapseEleven').collapse('show');
$(".img-change").attr("src", "assets/img/arrow_right.png");
}
$('h1.change:eq('+(step-1)+')').trigger("click", step);
}
</script>
</script>
<script>
$('h1.change').click(function (e, step){
var img1 = 'assets/img/arrow_right.png';
var img2 = 'assets/img/arrow_down.png';
if(step) $(".img-change").attr("src", img1);
var index = $(this).attr('index');
var element = $('img[index='+index+']', this);
if(element.attr('src') === img1){
element.attr('src',img2);
}else if(element.attr('src') === img2){
element.attr('src',img1);
}
});
</script>
Try putting in the function
next()
a code to change the images:$(".img-change").attr("src", "assets/img/arrow_right.png");
– Sam
@sam solved, but another problem appeared, can help me? Now it closes, however, does not open the next arrow to the next Collapse. Like, when you click the button, it opens the next Collapse and closes the current one, the current one changes with the code you passed, but the next one doesn’t change and shows that it is open, the icon remains closed while it is open. Could you help me? Anything, post the answer!
– EduardoBacarin
Remove all the code I suggested. Change the line
var element = $('img[index='+index+']');
forvar element = $('img[index='+index+']', this);
– Sam
Still unsuccessful, the arrows remain closed every Collapse change
– EduardoBacarin
You only have 2 collapses? The button is always onclick="next(2)"?
– Sam
No, I have 12 collapses, the button is always next(1), next(2), next(3), and so on.
– EduardoBacarin
Okay, these buttons go inside the collapses, each one?
– Sam
Yes, each one is within a Collapse, want me to post the code of one of the collapses?
– EduardoBacarin
See if it goes like this: https://jsfiddle.net/hc9fd540/
– Sam
That’s exactly what I want
– EduardoBacarin