I am looking to implement a feature with multiple drop-down menus using list items. The functionality I desire is that when the user clicks on a ul element, the list items should drop down. Then, upon clicking on a specific list item, the value of that item should replace the placeholder value in the existing list.
I came across a helpful code snippet that demonstrates this behavior, but I am having trouble implementing it in my CodePen project.
As I am not very experienced in JavaScript, I would greatly appreciate any guidance you can provide.
Is there a way to make my code behave like a standard select tag? I have chosen not to use the select tag due to the custom styling requirements that are not possible with select and option tags.
$(document).ready(function() {
$("ul.which-way").on("click", function() {
$(this).find('li').toggleClass("open-list");
$(this).find('open-list').css("display", "block");
});
$("li.cadja").on("click", function() {});
});
.which-wrapper {
width: 100%;
max-width: 300px;
}
ul.which-way {
margin: 0;
list-style: none;
background-color: grey;
margin-bottom: 5px;
}
ul.which-way li:not(:first-child) {
display: none;
}
ul.which-way {
cursor: pointer;
padding: 0;
}
li.open-list {
display: block !important;
}
.find {
margin-bottom: 10px;
display: inline-block;
width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="which-wrapper">
<div class="drowpdown-one dropdown">
<ul class="which-way">
<li class="which-init">Unguided I-Day Return Trips</li>
<li data-value="value 2" class="cadja"><span class="value">darling-wine-hops-day-by-which-way</span>Darling Wine & Beer Trip</li>
<li data-value="value 3" class="cadja"><span class="value">mamre-werf-khwa-ttu-culture-day-by-which-way-trips</span>Culture & Adventure Trip</li>
<li data-value="value 4" class="cadja"><span class="value">cape-west-coast-wildlife-fossil-trip</span>Wildlife & Fossils Trip</li>
</ul>
<a href="#" id="trip" class="find">FIND YOUR TRIP</a>
</div>
<ul class="which-way">
<li class="which-init">Unguided I-Day Return Trips</li>
<li data-value="value 2"><span class="value">darling-wine-hops-day-by-which-way</span>Darling Wine & Beer Trip</li>
<li data-value="value 3"><span class="value">mamre-werf-khwa-ttu-culture-day-by-which-way-trips</span>Culture & Adventure Trip</li>
<li data-value="value 4"><span class="value">cape-west-coast-wildlife-fossil-trip</span>Wildlife & Fossils Trip</li>
</ul>
<a href="#" id="trip" class="find">FIND YOUR TRIP</a>
</div>
</div>