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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:15:39+00:00 2026-05-18T09:15:39+00:00

I am trying to implement :random selector which selects a random element from a

  • 0

I am trying to implement “:random” selector which selects a random element from a stack of elements.

Here’s the code: http://jsfiddle.net/nuSWF/

The problem is the selector sometimes tries to select an element which does not exist(out of index). So I prepared the demo code which highlights the cause but I don’t understand why. I seems it is a bug or something.

P.S: I know I could select a random element with other methods but this time I have to implement this, also wondering what’s going on inside.

  • 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-18T09:15:39+00:00Added an answer on May 18, 2026 at 9:15 am

    What you’re seeing with the stack length is normal, it’s just evaluating the :random selector on all <a> elements in mydiv1 before the > child selector, so the length at that point is 4.

    For example, this would produce the result you’re expecting:

    var elements2 = $('#mydiv1>a').filter(':random');
    

    You can test it out here.


    So what’s happening overall is your selector is indeed filtering to random <a> elements…but those may or may not be further filtered out by the > child selector later (if they’re under a <span>, they get filtered). This is true of all selectors if you think about it…any filter you perform just reduces the set of elements…they may further filtered later by more selectors.

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

Sidebar

Related Questions

I'm trying out this nice way of customizing grouped UITableViewCell backgrounds: http://code.coneybeare.net/how-to-make-custom-drawn-gradient-backgrounds I've implemented
Am trying to implement a generic way for reading sections from a config file.
I'm trying to implement a weighted random numbers. I'm currently just banging my head
I'm trying to implement a lagged Fibonacci pseudo-random number generator for integers up to
I'm trying to implement a Remember Me login functionality for an ASP.NET MVC site
I am trying to implement a network core-periphery measure from an article (link: Borgatti
I'm trying to implement a function which allows the user to input some type
I am trying to implement random salt md5 algorithm on an existing application. User
I'm trying to implement a gaussian distributed random number generator in the interval [0,1].
hey everybody i am trying to implement code for finding order statistic but i

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.