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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:11:02+00:00 2026-05-10T17:11:02+00:00

<div id=myDiv> <a>…</a> <a>…</a> <a>…</a> <a>…</a> <a>…</a> <a>…</a> </div> If you wanted to select

  • 0
<div id='myDiv'>      <a>...</a>      <a>...</a>      <a>...</a>      <a>...</a>      <a>...</a>      <a>...</a> </div> 

If you wanted to select the 2nd, 3rd and 4th a tags in the above example, how would you do that? The only thing I can think of is:

$('#myDiv a:eq(1), #myDiv a:eq(2), #myDiv a:eq(3)') 

But that doesn’t look to be very efficient or pretty. I guess you could also select ALL the as and then do run .each over them, but that could get very inefficient if there were a lot more as.

  • 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-10T17:11:02+00:00Added an answer on May 10, 2026 at 5:11 pm

    jQuery slice() function taking indexes of the first and the last needed elements selects a subset of the matched elements. Note what it doesn’t include last element itself.

    In your particular case you should use

    $('#myDiv a').slice(1, 4) 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

example $('div.mydiv').checkifonlyone().css('background-color', 'red'); or maybe $('div.mydiv').filter(':checkifonlyone').css('background-color', 'red'); I expect that there is only one
I would like to replace div tags for p tags but only when the
#mydiv { position:absolute; left:0px; top:0px; width:83px; height:83px; } <div id=mydiv></div> That's my style for
If I do this: *{padding:0} div#myDiv{padding:10px;} Will that behave like any normal styling in
I select some paragraphs inside a div: $('#myDiv p.p1, #myDiv p.p2').text(); My problem is
I have a scriptaculous function that I need to change to Jquery. $$(div.mydiv a).each(
I have a <div name="myDiv">0</div> . I try to write a test that myDiv
<a rel=abc href=#mydiv>link</a> <div id=mydiv>content</div> If rel=abc, find element with ID that matches href
var $myDiv = $(div#myDiv);//example 1 $myDiv.val(); //example 1 var myDiv = $(div#myDiv); //example 2
<div id=mydiv> <p> <b><a href=mypage.html>This is an example<a>.</b> <br> This is another example. </p>

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.