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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T07:08:36+00:00 2026-05-12T07:08:36+00:00

Very new to jQuery, if dupe question sorry at this point not even sure

  • 0

Very new to jQuery, if dupe question sorry at this point not even sure I am using correct verbiage.

I need to add a li item to a ul based on a click event of a ListBox (user selects text and a new li is added with the selected text). And I need to add a icon, label and input on the li item. The icon needs to be a ‘remove’ icon.

How can I wire up the function to remove the newly added li item via jQuery?

Here is what I have tried;

        $(function() {
        function addSelectedWordCriteria() {
            var selectedWord = $("#wsWords").val();
            $("#wsCriteriaList").append("<li><a href='#' class='wsCriteriaRemove'><span class='ui-icon ui-icon-circle-close'/></a><em class='wsFilteredWord'>" + selectedWord + "</em><input type='textbox' maxlength='200' class='wsFilteredWords'/></li>");
            $("#wsCriteriaList a:last").bind("click", "removeSelectedWordCriteria");
        };

        function removeSelectedWordCriteria() {
            $("#wsCriteriaList").selected().remove();
        }

    })

<%= Html.ListBox("wsWords", ViewData["Words"] as IEnumerable<SelectListItem>) %>    

<ul id="wsCriteriaList">    
</ul>

Thanks for any suggestions.

  • 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-05-12T07:08:36+00:00Added an answer on May 12, 2026 at 7:08 am

    To your immediate question, since the click event gives you a reference to the element that sent the event, you could use it quickly determine what should be removed:

        function removeSelectedWordCriteria() {
            $(this).parent().remove();
        }
    

    Other things I may change about this code:

    1. As ScottE pointed out, this could be a great place to use the new live function. Outside of your addSelectedWordCriteria method, you should be able to put in:

      $("#wsCriteriaList a").live("click", "removeSelectedWordCriteria");
      

      And that will register all of your a tags with the same event even as they get added.

    2. Speaking of a tags, I’m not sure if you really need yours. All you really want is to be able to click the span that contains the remove image. Since you’re not actually using a link, personally, I would take out the anchor tag all together and put the click event directly on the span tag. You could then give it a class for the above live function.

    Let me know if you have additional questions.

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

Sidebar

Related Questions

I'm very new to jQuery but keen to learn. Because of this I'm using
I am very new to Jquery so please excuse this noobie question. I am
Guys i am very new to jQuery. I have started using the auto complete
Im very new to all coding including jquery. I though this would have been
I am very new to web development. I am currently using tablesorter jquery plugin
I am very new to jquery and need some help. I am trying to
I am very new on jquery, today i tried this following code $(#new).click(function() {
How do you make this code shorter, i'm very new to jquery but i
im very new to jquery/javascript. So here goes, I found this js code for
I'm very new to jQuery. I need to display customer testimonials from a database

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.