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

The Archive Base Latest Questions

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

i have for example: <span id=name1>name1</span> <span id=name2>name2</span> <span id=name3>name3</span> <span id=name4>name4</span> <span id=name5>name5</span>

  • 0

i have for example:

<span id="name1">name1</span>
<span id="name2">name2</span>
<span id="name3">name3</span>
<span id="name4">name4</span>
<span id="name5">name5</span>

i must use:

$("#name1").click(function(){
    $(this).css('background-color', 'red');
});
$("#name2").click(function(){
    $(this).css('background-color', 'red');
});

etc

i would like somethings:

$("#name  [1-5] ").click(function(){
    $(this).css('background-color', 'red');
});

i dont will add class. i would like make this for id and regular expression.

  • 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-24T16:44:23+00:00Added an answer on May 24, 2026 at 4:44 pm

    You have a few options:

    1. Use a class. It’s easy to add, and is exactly the right use for them in this instance. It will also be fastest.

    2. Use a loop:

      for(var i = 1; i <= 5; i++) {
      $(“#name” + i).click(function(){
      $(this).css(‘background-color’, ‘red’);
      });
      }

    3. Use attribute selectors: $('span[id^="name"]') That will grab all spans with an id that starts with “name”. Just know, this is the slowest option, so I would avoid it if you can.

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

Sidebar

Related Questions

For example, we have some CSS rules to define our form layout. We use
Can I have an identity (unique, non-repeating) column span multiple tables? For example, let's
I have an example function below that reads in a date as a string
Let's say for example I have this code: <input type=file id=file name=> <input class=uploadarea>
If I have a span tag like this: <span>Hi<br />SecondLine</span> And I call this
I have a list of objects, each with a few fields, like this: function
I have this simeple jQuery code: $('#category_name').change(function() { alert('Handler for .change() called.'); var category
I have a <form> that looks like this: <form> <input type=text name=name id=name /><span
I have example of code below. <script type=text/javascript src=assets/scripts/somescript.php>. </script> So, will my browser
If I have example.com/dir and dir is basically a folder in the example.com server,

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.