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

  • Home
  • SEARCH
  • 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 129039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:43:50+00:00 2026-05-11T05:43:50+00:00

Is there a built in method or defacto default plugin that will let you

  • 0

Is there a built in method or defacto default plugin that will let you automatically assign an unique ID to an element in jQuery, or do you need to implement something like this yourself? I’m looking for the jQuery equivalent to Prototype’s identify method

Here’s an example. I have some HTML structure on a page that looks like this

<span id='prefix_1'>foo bar</span> ... <div id='foo'>    <span></span>    <span></span>    <span></span> </div> 

I want to assign each of the spans an ID that will be unique to the page. So after calling something like this

$('#foo span').identify('prefix');   //fake code, no such method 

The rendered DOM would look something like this

<span id='prefix_1'>foo bar</span> ... <div id='foo'>    <span id='prefix_2'></span>    <span id='prefix_3'></span>    <span id='prefix_4'></span> </div> 

Is there anything official-ish/robust for jQuery, or is this something most jQuery developers roll on their own?

  • 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. 2026-05-11T05:43:51+00:00Added an answer on May 11, 2026 at 5:43 am
    jQuery.fn.identify = function(prefix) {     var i = 0;     return this.each(function() {         if(this.id) return;         do {              i++;             var id = prefix + '_' + i;         } while($('#' + id).length > 0);                     $(this).attr('id', id);                 }); };  $('span').identify('test'); 

    Tested this on:

    <span id='test_2'></span> <span>test1</span> <span>test2</span> <span>test3</span> 

    Turned it to:

    <span id='test_2'></span> <span id='test_1'>test1</span> <span id='test_3'>test2</span> <span id='test_4'>test3</span> 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 172k
  • Answers 172k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer [ms uniqueTilecacheKey] That's what's wrong. A selector is essentially just… May 12, 2026 at 2:24 pm
  • Editorial Team
    Editorial Team added an answer What exact problems are you having? From the sounds of… May 12, 2026 at 2:24 pm
  • Editorial Team
    Editorial Team added an answer Since you have an exact format, you can use DateTime.ParseExact… May 12, 2026 at 2:24 pm

Related Questions

Is there an easy way to capitalize the first letter of a string and
I have a very large javascript file I would like to load only if
Is there a built in method to handle urls like Default.aspx/mycontent or do I
Is there a quick way to join paths like the Join-Path function in Powershell?

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.