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

  • Home
  • SEARCH
  • 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 6793801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:08:38+00:00 2026-05-26T18:08:38+00:00

I have the following structure in a form: <div class=’full’> <div class=’half’> <label>Book</label> <select

  • 0

I have the following structure in a form:

<div class='full'>
  <div class='half'>
    <label>Book</label>

    <select class='collection_ID'>
      <option></option>
      <option value="1">Geen leuk boek / &euro; <span>14.50</span></option>
      <option value="2">Cool boek! / &euro; <span>24.50</span></option>
    </select>
  </div>

  <div class='half'>
    <label>Find a book</label>
    <input type='text' class='invoke_search'>
  </div>
</div>

<button class='clone'>Another Book</button>

And here is my question. I have an input field

<input type='text' class='invoke_search'>

If a user decides to type some text and then moves on (i.e blur event) he/she wants to search a book by title in the pretty close to it.

My jQuery function is the following:

$('.invoke_search').live('blur', function()
{  
  var needle   = this.value;
  var haystack = $(this).parent().parent().find('select').children();

  search(needle, haystack);
});

It’s on a .live() event listener (or however you call that), because the clone button will create a copy/clone of the .. so a user can add more books to the form, this also means that I cannot use a unique ID on the , since the user has to search in a single for an option and not in every select.

Now to get to my question, the following part is kind of hardcoded:

var haystack = $(this).parent().parent().find('select').children();

So I am looking for a way to use something like:

$(this).closest('select');

As if my form structure looked like:

<div class='full'>
  <label>Book</label>

  <select class='collection_ID'>
    <option></option>
    <option value="1">Geen leuk boek / &euro; <span>14.50</span></option>
    <option value="2">Cool boek! / &euro; <span>24.50</span></option>
  </select>

  <label>Find a book</label>
  <input type='text' class='invoke_search'>
</div>

This would make styling pretty hard, so is there a way to use .closest() or .find() in some smart way instead of ‘hardcoded’ parent().parent().find()?

Thanks in advance

  • 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-26T18:08:39+00:00Added an answer on May 26, 2026 at 6:08 pm

    If there’s always a <div class="full"> wrapper then perhaps this would work:

    var $select = $(this).closest('.full').find('select');
    

    You just need something that contains both your <input> and <select> that can easily be identified using a selector, then hand that selector to closest to find the starting point for find.

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

Sidebar

Related Questions

I have the following structure: <form> <div class=content> ... </div> <div class=action> <p>Select <a
I have a form of following structure ROR code form_tag class='remote_form' remote=>true { some
I have a structure like the following: <form> <input type=text /> <input type=text />
I have the following structure: class Base { } class Child : Base {
I have the following structure public class MyClass : MyBaseClass<System.Int32> { } In a
I have the following structure: <div id=container> <div id=someid1 style=float:right></div> <div id=someid2 style=float:right></div> <div
I have the following structure: class FeatureType(models.Model): type = models.CharField(max_length=20) def __unicode__(self): return self.type
I have an html form that has the following structure: <input type=text name=title />
I have the following structure in a Windows Form: Form (AutoResize = true, AutoSizeMode
I have a table with the following structure GUID uniqueidentifier with default value newid(),

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.