Miva Merchant Development by Scot's Scripts

BOOTSTRAP: Change Icons for Collapse Open/Closed

Miva Knowledge Base
BOOTSTRAP: Change Icons for Collapse Open/Closed

WARNING:

This information is offered "AS IS" for internal reference only. Use at your own risk.
Does AI actually understand your Miva Merchant store? Our smart JSON-LD schema generator makes sure it does. Contact us to get started. (more info)

BOOTSTRAP: Change Icons for Collapse Open/Closed

Scot Ranney • December 22, 2023 (updated: February 22, 2024)


THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED;
THE AUTHOR DISCLAIMS ALL LIABILITY FOR ANY DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR STORE DISRUPTIONS ARISING FROM ITS USE.


Change the open and closed icon when using collapses in Bootstrap. 

Feb 2024 Update: This now works for any collapse toggle without js for every collapse ID.

Requirements: Font Awesome, Bootstrap, and Jquery

1. Add toggle-collapse class to the trigger, in this case the button.

2. Add toggle-icon class to the font awesome icon call.

3. Include js below jquery call

<button class="toggle-collapse btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample" aria-expanded="false" aria-controls="collapseExample">
	<i class="toggle-icon fa fa-caret-right"></i> Click Me One
</button>

<div class="collapse" id="collapseExample">
	content in collapse ....
</div>

<button class="toggle-collapse btn btn-primary" type="button" data-bs-toggle="collapse" data-bs-target="#collapseExample2" aria-expanded="false" aria-controls="collapseExample2">
	<i class="toggle-icon fa fa-caret-right"></i> Click Me Two
</button>


<div class="collapse" id="collapseExample2">
	content in collapse ....
</div>

This goes under Jquery:

<script>
	$('.toggle-collapse').click(function(){
		$(this).find('.toggle-icon').toggleClass('fa-caret-right fa-caret-down');
	});
</script>

https://www.scotsscripts.com/mvblog/bootstrap-change-icons-for-collapse-openclosed.html

mvkb_bootstrap mvkb_jquery