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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:37:39+00:00 2026-05-12T23:37:39+00:00

My HTML is something like this : <select> <option>ABC (123)</option> <option>XYZ (789)</option> </select> What

  • 0

My HTML is something like this :

<select>
    <option>ABC (123)</option>
    <option>XYZ (789)</option>
</select>

What I’m trying to do is: using JQuery and a regex, I replace the “(” with <span>( here’s my JQuery line:

$(this).html($(this).html().replace(/\(/g,"<span>("));

It’s working as intended in Firefox, chrome and safari, but (as usual) not behaving correctly on IE6/IE7 (the text after “(” just get removed)

Any thoughts ?

PS: I’m doing it this way because I need “(number”) to be in a different color, and <span> in a <option> is not valid.

  • 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-12T23:37:40+00:00Added an answer on May 12, 2026 at 11:37 pm

    You’re saying that span in an option is not valid, and yet that’s exactly what you’re trying to add. Invalid code isn’t prettier just because it happens to be valid at load-time, if you know you’re going to mess it upp later. So really, if that’s your only concern, do add this span declaratively in your HTML, rather than injecting it later.

    But if you want to fix this, I think it might help if you rewrite the regex to cover the entire tag. In a lot of cases, IE doesn’t let you just change the HTML to whatever, but will use its own internal representation to fix up the code, according to its own preferences. When you write a table, for instance, IE will always internally infer a tbody, even if there isn’t any in the code. In the same manner, if you inject a <span> and there’s no </span>, IE might insert one by itself. To get around this, make sure you inject the code in its entirety in one go:

    $(this).html($(this).html().replace(/\((.*?)\)/g,"<span>($1)</span>"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do something like this: <div id=aa> <select><option>1</option></select> <select><option>a</option></select> </div> <div id=bb></div>
I have HTML something like this <div id=foo> <select> <option> one </option> </select> </div>
I have something like this in HTML: <select name=selection> <option id=1>First Option</option> ... </select>
I have an ASP.NET MVC form laid out something like this: @using (Html.BeginForm(null, null,
Using jQuery 1.6.2 HTML that I'm operating on <select id=langId> <option value=0>Argentina - Spanish</option>
in my .aspx page i have something like this: <select id=seltemp onchange=calltemp()> <option value=0
I have an html select: <select> <option>Choose one</option> </select> Using jQuery, is there an
My goal is to have something like a select option in a HTML form,
I am using the Perl CGI module. If I have HTML like this <select
i have my html something like this... <div class = content> <div class =

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.