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

  • Home
  • SEARCH
  • 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 8999737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:13:11+00:00 2026-06-16T00:13:11+00:00

I would like to remove the default functionality of clicking anywhere on a list

  • 0

I would like to remove the default functionality of clicking anywhere on a list item for it to be removed. Instead, I’d like to add a custom remove button that deletes the list item. Here’s what I’ve got so far.

<pre>
var sl = $('select#api_product').selectList({
  instance: true,
  clickRemove: false,
  onAdd: function (select, value, text) {
    $('.selectlist-item').last().after('<span class="delete"></span>');
  }
});
$('<span class="delete"></span>').insertAfter('.selectlist-item').last();
</pre>

Using this code, I’m able to remove the click target on the list item and add span tag which has a delete icon as a bg image. However, I don’t know how to remove the list-item and select option after clicking the span tag.

  • 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-16T00:13:12+00:00Added an answer on June 16, 2026 at 12:13 am

    I haven’t used selectList before, but a quick glance and some quick jsfiddle work (I borrowed one of the selectList examples) at it makes it look like adding a delegated event handler to the selectList classed ul should be able to take care of it.

    One caveat: the easiest way to do this for selection is to put the .delete span inside the appropriate li. Personally I think it’s also the closest to being semantically correct, since that delete “belongs” to that particular li. There are a couple of different ways to handle an approach where the deletes are outside of the li and that shouldn’t be terribly hard to figure out, but this was faster to reach a working demonstration for me:

    var sl = $('select#simple-usage-select-1').selectList({
      instance: true,
      clickRemove: false,
      onAdd: function (select, value, text) {
        $('.selectlist-item').last().append('<span class="delete"></span>');
      }
    });
    
    $('.selectlist-list').on('click', '.delete', function(event) {
     sl.remove($(this).parent().data('value'));
    });
    

    Basically selectList has a specific remove(value) function which then removes both the element and de-selects it within the list, you just have to go back to your selectList element and call that remove function using the value of the item being removed, which selectList stores via data() as value.

    I also removed your insertAfter as it seems completely unnecessary. Note the change to ‘append’ in the onAdd function. If your .delete span has to be in a following rather than contained element, you will either need to use sibling selectors or attach the data to the span as well when it is created, or use some similar method.

    Note: if you’re creating your selectlists on the fly you will need to attach the .on to something containing them, and probably change the selector to '.selectlist-item .delete' to keep it specific.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to remove border on a gtk.Button and also set its size
I can't add a not null constraint or remove a default constraint. I would
I would like to remove all the labels such as the city names that
I have created two custome membership providers that I would like to add to
maven-clean-plugin removes target folder by default, but I would also like it to remove
I would like to remove all trailing zeros without truncating or rounding the number
I would like to remove all lines from a textfile which contain a certain
I would like to remove the configuration out of my app.js and split it
I would like to remove all twitter nicknames (@xxx) from a string like this:
I would like to remove the queries information from the website. I am using

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.