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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:24:40+00:00 2026-05-24T06:24:40+00:00

I have code that adds list items to an unordered list, and associated with

  • 0

I have code that adds list items to an unordered list, and associated with each list item is a button the user can click to delete that item out of the list. This happens dynamically (ie. they select something from a modal screen that needs to be added back to this unordered list). Usually the value of the item is just an int. And in this case my code all works fine.

However if the value of the item is a string (because sometimes I need to deal with multiple ids represented as the one item) then the remove doesn’t do anything.

So at run time it can generate html like this (as grabbed from firebug)

<ul id="AgencySpecialism-selected-items" class="multi-select multi-select-selector">
 <li>
<label>Spec 1/Spec 2</label>
<input id="AgencySpecialism-3|1" type="hidden" value="3|1" name="AgencySpecialism-3|1">
<button title="Clear selection" style="width: 28px;" onclick="AgencySpecialism_clear('3|1');return false;"> X </button>
</li>
</ul>

My javascript clear function is:

function <%= ViewData["ControlId"] %>_clear(id) {   

        <% if (Model.MultiSelectMode) { %>
        alert('#<%= Model.ControlId %>-' + id);   
        alert($('#<%= Model.ControlId %>-' + id).val());
            $('#<%= Model.ControlId %>-' + id).closest('li').remove();            
            $('#<%= Model.ControlId %>_SelectedSpecialisms').val($('#<%= Model.ControlId %>_SelectedSpecialisms').val().replace(id + ",", ""));
        <% } else { %>

First alert shows

#AgencySpecialism-3|1

Second alert shows

Undefined

So it looks like it’s saying that control doesn’t exist – but based on the html markup – it does… ?!

So my end result is I need this line to work like it’s supposed to:

$('#<%= Model.ControlId %>-' + id).closest('li').remove();

If I was to pass in

AgencySpecialism_clear(4)

or

AgencySpecialism_clear('4')

then the clear works as expected. The only difference seems to be one is pipe delimited instead of a single value 🙁

Any ideas would be appreciated. I even tried copying and pasting the actual rendered id into the clear method.. but it still believes its val is undefined.

edit – sorry for the .net mvc stuff thrown in there – however the issue is related to the jquery part of it 🙂

  • 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-24T06:24:41+00:00Added an answer on May 24, 2026 at 6:24 am

    William is right, you need to escape the pipe:

    <div id="test|1">Test</div>
    
    alert($('#test\\|1').html());
    

    You will want to do:

    '#<%= Model.ControlId %>-' + id.replace("|", "\\|")
    

    http://jsfiddle.net/ryyzp/1/

    The double backslash is because you need to have’\|’ in the jQuery selector so you are actually escaping the 2nd blackslash with the first.

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

Sidebar

Related Questions

Basically what I have here is a button that adds a new list item
I have this code which applies a counter to each item on the list.
Following on from this question I now have code that can attach to a
I have some code that gives a user id to a utility that then
I have an unordered list with elements and I want to append an item
I have code that references a web service, and I'd like the address of
I have code that looks like the following, which works fine for displaying the
I have code that looks like: //System.Data.IDataRecord dr try { Consolidated = Utility.NullConvert.ToBool(dr[Constants.Data.Columns.cConsolidated], false);
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName
Hashtables have a syncroot property but generic dictionaries don't. If I have code that

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.