Require assistance in adjusting a personalized dropdown menu and updating the selected value

I have created a unique custom dropdown feature as shown below: view image description here

Upon selecting an option from the list, the main value will update and a label will float above it.

view image description here

$(".custom-dropdown-main").click(function(){ 
  $(".custom-dropdown").toggle(); 
});
.create-new-budget-value-date {
    margin: 30px 0 10px;
    padding: 10px 0;
    border-top: 1px solid #d8d9dc;
    position: relative;
}

.create-new-budget-value-date:before {
    content: "";
    background: url(../images/up-arrow.png) no-repeat 0 0;
    position: absolute;
    top: -14px;
    left: 100px;
    width: 22px;
    height: 14px;
}

.new-budget-value-select {
    width: 250px;
    border: 1px solid #d8d9dc;
    border-radius: 5px;
    padding: 2px 10px;
    min-height: 45px;
}

.new-budget-value-select .custom-dropdown-main {
    display: block;
    text-decoration: none;
    margin-top: 10px
}

.new-budget-value-select .custom-dropdown-main .glyphicon-menu-down {
    float: right;
}

.new-budget-value-select .custom-dropdown {
    margin-top: 5px;
}

.new-budget-value-select .custom-dropdown .dropdown-item {
    display: block;
    padding: 3px 2px;
}

.new-budget-value-select a:hover {
    text-decoration: none;
}

.new-budget-value-select .custom-dropdown .dropdown-item:hover {
    background: #e6e6e6;
    color: #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="new-budget-value-select">
   <a class="custom-dropdown-main" href="#" id="custom-select">
   Budget <span class="glyphicon glyphicon-menu-down"></span></a>
   <div class="custom-dropdown" style="display: none;">
      <a class="dropdown-item" href="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <a class="dropdown-item" href="#">Something else here</a>
   </div>
</div>

Answer №1

$(".custom-dropdown-main").click(function(){ 
  $(".custom-dropdown").toggle(); 
});

$(".custom-dropdown .dropdown-item").on('click', function() {
  $(".custom-dropdown-main").text($(this).text());
  $(".custom-dropdown-main").prepend('<span class="label">Budget</span>');
  $(".custom-dropdown").hide();      
});
.create-new-budget-value-date {
    margin: 30px 0 10px;
    padding: 10px 0;
    border-top: 1px solid #d8d9dc;
    position: relative;
}

.create-new-budget-value-date:before {
    content: "";
    background: url(../images/up-arrow.png) no-repeat 0 0;
    position: absolute;
    top: -14px;
    left: 100px;
    width: 22px;
    height: 14px;
}

.new-budget-value-select {
    width: 250px;
    border: 1px solid #d8d9dc;
    border-radius: 5px;
    padding: 2px 10px;
    min-height: 45px;
}

.new-budget-value-select .custom-dropdown-main {
    display: block;
    text-decoration: none;
    margin-top: 10px
}

.new-budget-value-select .custom-dropdown-main .glyphicon-menu-down {
    float: right;
}

.new-budget-value-select .custom-dropdown {
    margin-top: 5px;
}

.new-budget-value-select .custom-dropdown .dropdown-item {
    display: block;
    padding: 3px 2px;
}

.new-budget-value-select a:hover {
    text-decoration: none;
}

.new-budget-value-select .custom-dropdown .dropdown-item:hover {
    background: #e6e6e6;
    color: #000;
}

.label {
    display: block;
    font-size: 12px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="new-budget-value-select">
   <a class="custom-dropdown-main" href="#" id="custom-select">
   Budget <span class="glyphicon glyphicon-menu-down"></span></a>
   <div class="custom-dropdown" style="display: none;">
      <a class="dropdown-item" href="#">Action</a>
      <a class="dropdown-item" href="#">Another action</a>
      <a class="dropdown-item" href="#">Something else here</a>
   </div>
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

occupy the full width of the available screen space (from one end of the container to the other

Currently, I am utilizing the Flexbox enabled version of Bootstrap 4 Alpha 3. Check it out on Jsfiddle body { background-color: lightgreen; } [class^="col"] { background: gold; border: 1px solid tomato; } <link href="https://cask.scotch.io/boo ...

Overlapping Flexbox elements causing stacking issues

My attempt to create a gallery layout with two larger blocks amidst smaller blocks is not functioning correctly. The large block is overlapping the two smaller blocks below it. Is there a way to prevent block overlapping using CSS? I have searched Stack O ...

Transforming an array of JSON objects into a Knockout observable array containing observable properties

My application utilizes an ajax call to fetch a JSON array. [ {"ID":2,"Name":"Name 1","CreatedOn":"/Date(1432892160000)/"}, {"ID":7,"Name":"Name 2","CreatedOn":"/Date(1432892160000)/"}, {"ID":8,"Name":"Name 3","CreatedOn":"/Date(1432892160000)/"}, {"ID":9 ...

Tips for invoking a custom function in jQuery with a delay when hovering

I've been struggling with my syntax, trying to achieve something simple. I have a function called 'displayUserinfo' that pops up a box with user information. It is triggered when the user clicks on an element with the class 'avatar&apo ...

Adjust the height of the container to accommodate responsive images automatically

Hello, I am trying to make the container height adjust automatically based on the responsive image it contains. The container's display is set to flex and the image is positioned between two divs with the class "text-block". These divs have a width of ...

Trouble with fetching data from external API due to cross-origin restrictions

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> <script> $(document).ready(function(){ $.get({ url: "http://www.dnd5eapi.co/api/races/", data ...

What could be the reason behind my alert message not showing up when the user fails to login correctly? Exploring Django, HTML, and CSS for answers

Below is the code snippet from my signIn.html file: {% if messg %} <script> aleart("{{messg}}"); </script> {% endif %} Here is a snippet of my Django View code: def postsign(request): email = request.POST.get("email" ...

The FormData function is unable to retrieve the input fields of a form

My Unique Code <!DOCTYPE html> <html> <body> <div id="custom-form-sample"> <form enctype="multipart/form-data"> <input type="text" name="custom-text" /> <input type="radio" name="custom-radio" ...

Pagination with Thymeleaf in Spring Boot

I'm facing a challenge with pagination and need help resolving it. Whenever I try to access the index page, I receive the following error message: There was an unexpected error (type=Internal Server Error, status=500). Exception evaluating Spring ...

Utilizing Bootstrap 5 to showcase a variety of images that adapt to different screen sizes

Using Bootstrap 5, I am attempting to utilize an img tag to showcase a different image depending on the device - mobile, tablet, or desktop. However, I am facing challenges in correctly setting the breakpoints for the wrapper divs using the display utiliti ...

Updating an already opened HTML page from a Java application

I am working with an application that generates an HTML page using Freemarker. Once the webpage is generated, I use Desktop to open it from the application as follows: public void openPage() { if (Desktop.isDesktopSupported()) { try { ...

Transform basic list into a two-dimensional array (grid)

Picture a scenario where we have an array: A = Array(1, 2, 3, 4, 5, 6, 7, 8, 9); We aim to transform it into a 2-dimensional array (a matrix of N x M), similar to this representation: A = Array(Array(1, 2, 3), Array(4, 5, 6), Array(7, 8, 9)); It's ...

Having trouble with aligning the wrapper div

I am looking to create a div with text inside it. Within that div, I also want another div that matches the same position and size. I have searched on various forums for a solution, but none of them seem to work when even a small detail is different. Curr ...

Utilizing JSON format, handling special characters, and storing data in a database

My friend approached me with a question and although I wanted to offer immediate help, I realized that seeking advice from others may provide better solutions. Situation: Imagine there is a Form that includes a RichText feature: DHTMLX RichText (). This R ...

Preventing duplicate submissions in Ajax by serializing form data

I'm having trouble preventing double submissions on my form when I rapidly press the button that triggers a click event. I attempted to disable the button after a successful submission, but it still submits twice. Here is my code: <script> $(do ...

Tips for initiating and terminating the evaluation of a condition at regular intervals using JavaScript

I'm currently working on a JavaScript application where I need to achieve the following: Periodically check every 5 seconds to see if there is an element with the 'video' tag on the page. Once an element with the 'video' tag ...

Utilizing Jest to Mock a jQuery Method within a Promise

I have created a function that utilizes a jQuery function named dataFunc, which is expected to return an object. Instead of testing the dataFunc function itself, I want to focus on testing the promise it produces. To achieve this, I need to mock the respo ...

Text alignment post-rotation

Whenever I rotate a span, the text inside does not align horizontally. As shown in the example below, we are facing alignment issues with three rotated spans. body{ padding-left:10px; } .bordered{ border-left: 2px solid gray; position: relative ...

Incorporating personalized jQuery (modal window) into a WordPress site

I created a unique jQuery modal/pop-up and now I am looking to integrate it into my WordPress site. HTML <div id="customDialog"> <form id="myForm" method="post"> <br><br><br> <p id=title name=title><b>S ...

Move the element outside of the parent container

I am in the process of creating a collapsible sidebar using bootstrap, and I am attempting to have a submenu appear outside of the sidebar when it is toggled to a mini navigation. For example: When the window size is greater than 767 pixels and you click ...