Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8162419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:42:14+00:00 2026-06-06T18:42:14+00:00

I am trying to make a dropdown menu that when you click dropdown a

  • 0

I am trying to make a dropdown menu that when you click dropdown a (in this case Item 3) the ul is showed and then when you click the li for example Item 2 it is posted and then Item 3 (the text between the a) would be replaced by item 2 and vice versa in the li. So far I have been unsuccessful in doing this. Any help would be greatly appreciated. This is what I have so far:

<div class="dropdown">
    <a href="#">Item 3</a>
    <ul data-id='<?php echo $row['_id'] ?>' data-url='<?php echo Uri::create('edit') ?>'>
        <li> Item 1 </li>
        <li> Item 2 </li>
        <li> Item 4 </li>
        <li> Item 5 </li>
        <li> Item 6 </li>
    </ul>
</div>



$('.dropdown a').click(function() {
    $(this).parent().children('ul').toggle();
    return false;
});


$('.dropdown li').click(function() {
    var url = $(this).parent().data('url'),
        id = $(this).parent().data('id'),
        status = $(this).text();

$.post(url, { status: status, id: id }, function() {

    });
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:42:15+00:00Added an answer on June 6, 2026 at 6:42 pm

    Solution sorts the LI’s after the text change and slides the dropdown closed again

    DEMO: http://jsfiddle.net/Ze7ej/

    /* must delegate handler due to html change during sorting*/
    $('.dropdown').on('click', 'li', function() {
        var $this = $(this),
            $parent = $this.parent(),
            $link = $parent.prev(),
            url = $parent.data('url'),
            id = $parent.data('id'),
            status = $this.text();
        $this.text($link.text());
        $link.text(status);
        $parent.slideToggle(function() {
            var list = $parent.children().get();
            list.sort(sortList);
            $parent.html($(list))
        });
    
        /* do ajax*/
    });
    
    
    function sortList(a, b) {
        return $.trim($(a).text()).localeCompare($.trim($(b).text()));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a CSS & JS based dropdown-menu. This example works in
I'm trying to make a CSS/javascript dropdown menu (based on this example . This
I'm trying to make it so that my dropdown menu shows when you click
I'm trying to make a navigation dropdown with jQuery that looks like this: <ul
I am trying to make a dropdown menu with pure html and css, but
I'm new to jquery and i'm trying to make a dropdown menu list like
I'm trying to make a small survey that populates the selections for the dropdown
i am trying to implement jquery's toggle method to make a dropdown menu, it
I am trying to build a CSS dropdown menu. The problem is that all
I'm trying to build my own custom dropdown menu that should remember it's vertical

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.