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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:43:39+00:00 2026-06-04T11:43:39+00:00

I have multiple select boxes in my document and some of them are load

  • 0

I have multiple select boxes in my document and some of them are load with page load and some of them created dynamically. for example:

<select>
    <option>select one</option>
</select>

<select></select>

<select>
    <option>select two</option>
</select>

<select>
    <option>select three</option>
</select>

<select>
</select>

and more are created dynamically some of with and some are empty.

I want to get the first empty select among them at page load and click on a button again want to get the first empty select box from the last one I get and continue this until no such select box further exists.

NOTE from the last one means,

If I get the first empty select box from first, then one button click search will start from that select box and continue until again get an empty select and so on.

  • 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-04T11:43:41+00:00Added an answer on June 4, 2026 at 11:43 am

    Try this:

    $('select:empty:first');
    

    but one think to note that, above selector only works if your select box are like
        
       

    <select></select> // even without any newline
    

    because :empty point element with no child, not event with newline or text node.

    So if your select is look like:
        
     

    <select>
    </select>
    

    above selector will fail. To get select like both type you can use

    $('select').filter(function() {
      return !this.innerHTML.replace(/\s/g,'').length;
    }).first();
    

    or as @gdoron mentioned

    $('select').filter(function() {
      return !$.trim(this.innerHTML);
    }).first();
    

    In my choice, second one is reliable.

    // solution to your recursive search
    
    $('select')
        .filter(function() { // filtering for empty select
            return !this.innerHTML.replace(/\s/g,'').length;
         })
        .first() // taking the first
        .addClass('lastIndentified'); // adding a class to keep track
    
    $('button#search').on('click', function() {
      // reference for last empty select
      var lastIndentified = $('select.lastIndentified');
    
      lastIndentified
          .nextAll('select') // searching for all select
          .filter(function() { // making filtering
               return !this.innerHTML.replace(/\s/g,'').length;
          })
          .first() // taking first one from lastIndetified
          .addClass('lastIndentified');
        lastIndentified.removeClass('lastIndentified'); // remove class from last empty select and pass it to new empty select
    
        // for example
        // calling function to process with last empty select
        processWithLastEmptySelect($('select.lastIndentified'));
    });
    
    function processWithLastEmptySelect(lastSelect) {
       // your code if needed
       lastSelect.css('border', '1px solid green');
    }
    

    Working Demo

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

Sidebar

Related Questions

So I have two multiple select boxes like this <select id=foo multiple=multiple> <option value=1>Option
I have a buch of multiple select boxes and I wanted to line them
I have two multiple select boxes. I need to use JQuery to drag selected
I have a page with multiple select boxes, as per the following: <select name=item-0-status
I have multiple select boxes on the page all of which share the same
I have multiple multi-select boxes with the same class and i want to unselect
I have multiple tables that need to be merged into one. SELECT name, SUM(money)
I have this HTML: <select multiple='multiple' size='3'> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> </select> Using
I have a form where a user can add multiple select boxes for multiple
I have two g:select comboboxes that I want to add to the multiple select

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.