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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:48:51+00:00 2026-05-22T16:48:51+00:00

I have a script that’s supposed to dynamically place divs containing group member names

  • 0

I have a script that’s supposed to dynamically place divs containing group member names inside one container div. These divs are ID’d by the concatenation of “groupMemberEntryDiv” and the group member’s e-mail address (which is unique in my system).

The problem is that using the IDs in jQuery selectors doesn’t work. I believe I’ve covered all the possible hangups that could be causing this problem:

  1. The presence of ‘@’ in e-mail addresses (element IDs cannot contain this character). I’ve fixed this by replacing them with ‘:’, which is allowed character. Also, since ‘:’ does not appear in valid e-mail addresses, I can use indexOf to parse the string and replace it with ‘@’ when I need to use the e-mail address again.
  2. The presence of ‘:’ and ‘.’ in (the now modified) e-mail addresses (jQuery may see them as pseudo-classes and classes respectively). Following the instructions in that page, I have tried to escape the characters. In fact, I lifted the .replace() function from that very link to do so.

Unfortunately, the selectors still won’t work. I’ve created a simple jFiddle to illustrate the problem.

Can someone please explain what’s going on?

  • 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-22T16:48:52+00:00Added an answer on May 22, 2026 at 4:48 pm

    This is because you are escaping the special characters (which is correct for the selector) but the ID doesn’t need to be escaped. Consider:

    $("#protectedGroupDiv100").append("<div id='groupMemberEntryDiv"  + emailString + "' class='groupMemberEntryDivs'>hey</div>");
    

    Generates:

    <div id="groupMemberEntryDivblahblah\:gmail\.com" class="groupMemberEntryDivs"></div>
    

    See how this creates an element with id of: #groupMemberEntryDivblahblah\:gmail\.com
    but later you use the selector of #groupMemberEntryDivblahblah\:gmail\.com which seems the same but what jQuery looks for is actually #groupMemberEntryDivblahblah:gmail.com. Since the ID of your element has backslashes in it, jQuery finds no match for the selector.

    To fix this set the ID before you escape it:

    $.each(emailArray, function(index, emailString){
        emailString = emailString.replace("@", ":");            //Element attributes cannot contain "@"
    
        $("#protectedGroupDiv100").append("<div id='groupMemberEntryDiv"  + emailString + "' class='groupMemberEntryDivs'>hey</div>");
    
        emailString = emailString.replace(/(:|\.)/g,'\\$1');    //Escape ':' and '.'
    
       alert($("#groupMemberEntryDiv"  + emailString).length);                  
    });
    

    Here is a modified jsFiddle.

    Though this works, I do not recomend having user emails in the markup. As others have hinted to it can lead to security issues.

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

Sidebar

Related Questions

I have a script that is one script in a chain of others that
I have a script that I only want to be running one time. If
I have a script that records files with UTF8 encoded names. However the script's
I have a script that appends some rows to a table. One of the
I have a script that is being inserted dynamically via another script. The code
I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example),
I have a script that retrieves objects from a remote server through an Ajax
I have a script that checks responses from HTTP servers using the PEAR HTTP
I have a script that takes a table name and generates a control file
I have a script that renders graphs in gnuplot. The graphs all end up

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.