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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:25:21+00:00 2026-05-26T19:25:21+00:00

I have a string: <li>&File</li> . What I would like to do is analyse

  • 0

I have a string: <li>&File</li>. What I would like to do is analyse the string inside the li element to find the location of the ampersand. Once found, I’d like to wrap the next character inside a span.

The logic behind this is relatively straightforward. Get the string position of &, remove it and then wrap the following character (i.e. string position + 1) in a span.

Could anyone suggest a suitable method in jQuery to wrap a single character of a string? I know it’s possible to wrap a block of HTML, but can one work on strings like this, or would it be better to create a custom function?

I should mention that the position of & will not always be at the beginning of the string, either. I was thinking to use Regular Expressions for finding its position, since I only want to parse the first occurance of an ampersand within the string, thus leaving later occurances untouched.

The ampersand is not a HTML entity – it’s simply & (and not &amp;).

Any help and insight most gratefully received…

  • 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-26T19:25:21+00:00Added an answer on May 26, 2026 at 7:25 pm

    Try follow:

    $(function(){
      $('ul>li:contains(&)').each(function(){
        var text = $(this).text();
        text = text.replace(/^&(\w){1}/, "<span>$1</span>");
        $(this).html(text);
      });
    });
    

    You can see example here.

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

Sidebar

Related Questions

I have this: Dim myTemp As String myTemp = System.DateTime.Now().ToString(MMMddyyyy_HHmmss) & .pdf System.IO.File.Copy(myFile, c:\
Let's presume that I have string like '=&?/;#+%' to be a part of my
I have a string like so: http://www.youtube.com/v/Nnp82q3b844&hl=en_US&fs=1& and I want to extract the Nnp82q3b844
I have a url string like this: http://www.google.com/cse?cx=017840637368510444960:ny1lmky7r-0&client=google-csbe&output=xml_no_dtd&q=simon+g I need to send this url
Let's say I have this string: Hello &, how are you? I'm fine! Is
I have a query string: a=1&b=2&c[1]=3&c[2]=4 etc… I want a NSDictionary where a =>
I have the following code string three() { return three; } void mutate(string& ref)
For example, suppose I have a class: class Foo { public: std::string& Name() {
I have a string that is HTML encoded: '''&lt;img class=&quot;size-medium wp-image-113&quot;\ style=&quot;margin-left: 15px;&quot; title=&quot;su1&quot;\
I have this string in PHP: $string = name=Shake & Bake&difficulty=easy; For which I

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.