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

The Archive Base Latest Questions

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

I have the jquery: $(.item) which gives me all elements of class item. I

  • 0

I have the jquery:
$(“.item”)

which gives me all elements of class item.

I need to select an item from the array I get from this method, and then find the item before this.

something like: $(“.item”).select(“#3”).prev() – except it should work 🙂

so, assuming I had the list of items:

<div id=1 class="item"></div>
<div id=2 class="item"></div>
<div class="somethingElse"></div>
<div id=3 class="item"></div>
<div id=4 class="item"></div>

I should get the “<div id=2></div>” item.

Any ideas?

  • 1 1 Answer
  • 3 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-11T22:43:09+00:00Added an answer on May 11, 2026 at 10:43 pm

    prev only looks at the immediate previous sibling. Try this:

    $('#3').prevAll('div.item').eq(0);
    

    That should get what you want. As mentioned by googletorp, doing $('.item').find('#3'); is redundant and slower. IDs are supposed to be unique so you should be fine to do $('#3') directly. Do note, however, that IDs, per the spec, are not supposed to start with numbers:

    ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens (“-“), underscores (“_”), colons (“:”), and periods (“.”).

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

Sidebar

Related Questions

I have jQuery code which looks something like this on Button1 Click $('table.result_grid tbody
I have a method which returns a persisted html template from a database. The
Ok, so I have this search box in which people typein a food item.
I have an array of elements: markers and a table which updates it's rows
I have two variables in a jquery code and if item.a not exist, it
I have the following function in my jQuery code: function checkUNSelectBox(item){ $('#DELETE option').each(function(){ <!--alert(item);-->
I have written a function which fires when a particular menu item is clicked.
I have jquery script which replaces a div when a href=#1 is selected. a
I have a jquery script which replaces a div (child1 with child2) when a
I have an ordered list which when each item is clicked it will toggle

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.