I have a dropdown list, I want to change dropdown button text acording to my dropdown items on click dropdown items
You have not mentioned the dropdown list code in your question based on which we will write a code, here we are presenting bootstrap supported dropdown list whose button text will change according to the selected tab.
Check by clicking on this dropdown button:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle my-toggle-button" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Home
</button>
<ul class="dropdown-menu" id="my-active-tab">
<li><a class="dropdown-item" href="#">Home</a></li>
<li><a class="dropdown-item" href="#">Services</a></li>
<li><a class="dropdown-item" href="#">Contect</a></li>
<li><a class="dropdown-item" href="#">About Us</a></li>
</ul>
</div>
<script>
$("#active-tab li").on("click", function() {
$('.my-toggle-button').text($(this).text());
});
</script>
If you still have a question about this, submit it in our Q&A community - Ask Question