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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:27:33+00:00 2026-05-18T11:27:33+00:00

I’m trying to create an outlook style To: / recipients list when I select

  • 0

I’m trying to create an outlook style To: / recipients list when I select contacts from a javascript address book I wrote.

I have a list of contacts in an addressbook which when selected, looks like this…

<div class="contact selected">
    <div style="clear: both;"></div>
    <div class="innertxt" id="c_e4f6ea43-03fd-4496-aa58-917a17e31206">
        <span id="Test User">
        <img width="48" height="48" src="/Content/Cache/4.gif"><a href="/Management/Employee/Edit/e4f6ea43-03fd-4496-aa58-917a17e31206" class="contact-link">Test User</a>
        <ul>
            <li>test.user@test.com</li>
            <li>123456789</li>
        </ul>
    </span></div>
</div>

and a recipient div which looks like this…

<div id="RecipientNames"></div>

I have some javascript that runs to select the anchor tag within this user and add that achor to my recipient field along with a delimiter ;

function ContactSelected(contact) {
    var contactLink = $(contact).find('div[id^="c_"] a');
    contactLink.clone().appendTo("#RecipientNames");
    $("#RecipientNames").append("; ");
}

The contact passed into this function is the entire contact element presented at the start of this question.

Thus I end up with….

<div id="RecipientNames">
  <a class="contact-link" href="/Management/Employee/Edit/e4f6ea43-03fd-4496-aa58-917a17e31206">Test User</a>; 
</div>

Problem

Given a RecipientNames div that has multiple recipients, what jquery can I use to remove the contact-link anchor tag and the following ‘; ‘.

<div id="RecipientNames">
  <a class="contact-link" href="/Management/Employee/Edit/e4f6ea43-03fd-4496-aa58-917a17e31206">Test User2</a>;
  <a class="contact-link" href="/Management/Employee/Edit/e4f6ea43-03fd-4496-aa58-917a17e31206">Test User2</a>;
  <a class="contact-link" href="/Management/Employee/Edit/e4f6ea43-03fd-4496-aa58-917a17e31206">Test User3</a>;
</div>

So, for example if I wanted to remove TesetUser2; which is the entire <a> tag plus the semi-colon after. In this particular case, it is the middle user and semi-colon being removed. But they can be removed in any order so it always needs to be the semi-colon following the contact specified.

How would I go about implementing the Remove function that will be called. I have tried the following but it was a guess and consequently does not work 🙂

public ContactRemoved(contact) {
     var selector = $(contact).find('div[id^="c_"] a').attr("href");
     var recipients = $("#RecipientNames");
     $(recipients).remove('a[href^="' + selector + '"]').remove("; ");
}

FINAL SOLUTION

    function ContactSelected(contact)
    {
        // append selected contact name to recipient list.
        var contactLinkSpan = $("<span>");
        var contactLinkClone = $(contact).find('div[id^="c_"] a').clone();
        contactLinkClone.appendTo(contactLinkSpan);
        contactLinkSpan.append("; ");
        contactLinkSpan.appendTo("#RecipientNames");
    }

    function ContactRemoved(contact) {
        // remove selected contact from recipient list.
        var selector = $(contact).find('div[id^="c_"] a').attr("href");
        $("#RecipientNames").find('a[href^="' + selector + '"]').parent().remove();
    }
  • 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-18T11:27:34+00:00Added an answer on May 18, 2026 at 11:27 am

    I would wrap each semicolon in a span tag (<span id="{associated_anchor_tag}">;</span>) and add an associative anchor tag identifier as an id attribute. When you are ready to delete a particular contact, find the appropriate span tag and perform a simple $.remove() on it

    Sample code below, should help in understanding the answer above

    Creating the span tag

    var contactLink = $(contact).find('div[id^="c_"] a');
    var contactLinkIdentifier = $(contact).find('div[id^="c_"]').attr("id");
    contactLink.clone().appendTo("#RecipientNames");
    $("#RecipientNames").append('<span id="'+contactLinkIdentifier+'">;</span>');
    

    Removing the correct node

     function contact_removed(contact) {
         var selector = $(contact).find('div[id^="c_"] a').attr("href");   
         var contactLinkIdentifier = $(contact).find('div[id^="c_"]').attr("id");
         var recipients = $("#RecipientNames");
         $(recipients).remove('a[href^="' + selector + '"]');
         $(recipients).remove(contactLinkIdentifier);
     }
    

    You can remove some lines of code if you simply add an id attribute to the anchor tag and simply call remove once

    EDIT:
    If you want the semicolon to be inside a <span> with the <a> tag, then simply create a new span tag and append to it the <a> tag clone. Some sample code below should help

    var contactLinkSpan = $("<span>");
    var contactLinkClone = $(contact).find('div[id^="c_"] a').clone();
    contactLinkClone.appendTo(contactLinkSpan);
    contactLinkSpan.append("; ");
    contactLinkSpan.appendTo("#RecipeintNames");
    

    And, when you are ready to delete, simply find the respective <a> tag, get its parent (which would be the <span> tag) and you can remove that from the DOM by calling $.remove()

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

Sidebar

Related Questions

No related questions found

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.