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 8538999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:15:27+00:00 2026-06-11T11:15:27+00:00

I have a select option, a list and a button. When the button is

  • 0

I have a select option, a list and a button. When the button is clicked it removes the selected option and put it in the list. And when the li in the list is clicked, it is put back in the select option and it removes itself. Here is my code:

                            <select id="selLanguage" >
                                 <option value="1">English</option>
                                 <option value="2">Spanish</option>
                                 <option value="3">German</option>
                            </select>

                             <ul id="ulLanguage">
                             </ul>

                             <button id="btnAddLanguage">Language</button>

            //ADD LANGUAGE
            $(function() {
                $("#btnAddLanguage")
                .button()
                .click(function() {

                    $("#ulLanguage").append("<li id='"+$("#selLanguage :selected").val()+"' onclick='remove(this);' style='cursor:pointer'>"+$("#selLanguage :selected").text() +" </li>");
                    $("#selLanguage option[value='"+$("#selLanguage :selected").val()+"']").remove();


                });
            });
            //REMOVE LANGUAGE
            $("#ulLanguage").on("click","li", function(){

                $("select#selLanguage").append("<option value='"+$(this).val()+"' >"+$(this).text()+"</li>");
                $(this).remove();
            });   

It works, but when i add the three options, i remove the three optiones and they are put back in the select (till here is ok), and i add one again and it removes all the options in the select, instead just the one selected. I dont have any clue about where i made my mistake and Im very new to jquery, so i had to ask this. Any help would be really appreciated. Thanks.

  • 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-11T11:15:28+00:00Added an answer on June 11, 2026 at 11:15 am

    There are several things missing:

    • Your second callback is outside the jquery ready callback
    • You inject back into the select an option which is closed as a li:

    append("<option value='"+$(this).val()+"' >"+$(this).text()+"</li>");

    • You don’t preserve the li.id value when you put back the item in the select, thus the error.

    A corrected version is below

            $(function() {
                $("#btnAddLanguage")
                .on('click', function() {
    
                    $("#ulLanguage").append("<li id='"+$("#selLanguage :selected").val()+"' style='cursor:pointer'>"+$("#selLanguage :selected").text() +" </li>");
                    console.log($("#selLanguage :selected").val());
                    $("#selLanguage option[value='"+$("#selLanguage :selected").val()+"']").remove();
    
    
                });
    
            //REMOVE LANGUAGE
            $("#ulLanguage").on("click","li", function(){
    
                $("select#selLanguage").append("<option value='"+$(this).attr('id')+"' >"+$(this).text()+"</option>");
                $(this).remove();
            });                 
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list like this: <select name=select_list_name id=list_id> <option value=>Select Option</option> <option value=value1>Option
I have a routine that dynamically changes a select list's selected option when the
I have the following drop down list: <select name=selSS1 id=select_value> <option value=val0>sea zero</option> <option
So I have a dropdown list <select id=theSelectId> <option value=volvo>Volvo</option> <option value=saab>Saab</option> <option value=mercedes>Mercedes</option>
I have this drop-down list of countries: <select name=country> <option value=>Country...</option> <option value=Afganistan>Afghanistan</option> <option
I have a select list of genders. Code: <select> <option>male</option> <option>female</option> <option>others</option> </select> I
I have a SELECT list as follows <select id=LIST> <option value=1>New York</option> <option value=2>Chicago</option>
I have a dropdown list in my django template: <select name=submit_new id=submit_new> <option value=Stdo>Studio</option>
Need help I have following code with classic asp <select name=state id=state> <option value=NJ>New
I have the following dropdown list box: <select name=DDLConditional1 size=1> <option selected=selected>is equal to</option>

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.