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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:39:06+00:00 2026-06-14T16:39:06+00:00

For example, I have the html block: <div class=span3> <div class=firstDiv></div> </div> <div class=span3>

  • 0

For example, I have the html block:

<div class="span3">
  <div class="firstDiv"></div>
</div>
<div class="span3">
  <div class="secondDiv"></div>
</div>

Replicas of this html block can be inserted using javascript, so I have a large number of these blocks one after another.

I’d like to hear perspective on whether putting id’s on all of these elements in order to work with them is a standard/efficient way to do things. I have a good way to put unique ids with matching suffixes on generated elements, like:

  ...
  <div class="span3">
    <div id="firstDiv_154 class="firstDiv""></div>
  </div>
  <div class="span3">
    <div id="secondDiv_154 class="secondDiv""></div>
  </div>

  <div class="span3">
    <div id="firstDiv_155 class="firstDiv""></div>
  </div>
  <div class="span3">
    <div id="secondDiv_155" class="secondDiv"></div>
  </div>
  ...

Then as a general rule, to do something to the secondDiv when I click the firstDiv in the set I could just do:

$('.firstDiv').on ('click', function(evt) {
  var idToFind = $(evt.target).attr('id').replace(/firstDiv/, /#secondDiv/)
  var $secondDiv = $(idToFind);
  // do something with $secondDiv
});

Are there more efficient ways to use id’s?

If not using id’s, I could use jQuery:

If I want to find the second element from the first:

$('.firstDiv').parent().next().children()

which would break if I rearranged elements too much,
or

$('.firstDiv').closest('.span3').find('.secondDiv')

which would be more robust, but is likely more resource intensive than the first jQuery method.

Which of all of these methods would you (experienced web devs, please) recommend?

  • 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-06-14T16:39:07+00:00Added an answer on June 14, 2026 at 4:39 pm

    It depends on what you’re trying to accomplish. If you need a way to uniquely identify an element and there is no other way in your current setup to do so, then unique id’s is a good way to go.

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

Sidebar

Related Questions

I have html like so: <div class=foo> (<a href=forum.example.com>forum</a>) <p> Some html here.... </div>
I have a base.html template that contains a list of links. Example: <div id=sidebar1>
Suppose we have this example: http://techdroid.kbeanie.com/2009/07/custom-listview-for-android.html with source code available here: http://code.google.com/p/myandroidwidgets/source/browse/trunk/Phonebook/src/com/abeanie/ How can
I'm new to cakephp and following this tutorial. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html I have created the blog
You can see an example here: http://users.telenet.be/prullen/portfolio_test.html I have set a padding of 100px
I have html: <div class=items-list-container> <div class=fieldset-item>Something</div> <div class=fieldset-item>Something 2</div> <div class=fieldset-item>Something 3</div> <div
I have the following HTML: <div class="selfClear" style="float: left; border: 1px solid black;"> ...floated
I'm loading new HTML/JS content using ajax and appending it to some div block
If I for example have <p> some long text </p> on my HTML page,
I have two html pages on my webserver www.example.com/desktop.html www.example.com/mobile.html In principle the content

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.