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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:32:43+00:00 2026-06-17T12:32:43+00:00

Consider a markup such as <select id=blah> <option value=3>Some text</option> <option value=4>Some text</option> <option

  • 0

Consider a markup such as

<select id="blah">
  <option value="3">Some text</option>
  <option value="4">Some text</option>
  <option value="8">Some text</option> // <---- target this tag based on value 7
  <option value="19">Some text</option>
</select>

Suppose I have a value with me, say 7. Is it possible to target the option tag whose value attribute is closest to 7 which, in this case, would be <option value="8">?

I’m aware of ^ which means starting with and $ which means ending with and was hoping if there is something like this to find the closest match for a given value.

  • 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-17T12:32:44+00:00Added an answer on June 17, 2026 at 12:32 pm

    I’ll go like this:

    http://jsfiddle.net/GNNHy/

    var $tmpOption = $('<option value="7">Some text 7</option>');
    $("#blah").append($tmpOption);
    var my_options = $("#blah option");
    my_options.sort(function(a,b) {
        if (parseInt(a.value,10) > parseInt(b.value,10)) return 1;
        else if (parseInt(a.value,10) < parseInt(b.value,10)) return -1;
        else return 0
    })
    
    $("#blah").empty().append( my_options );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this markup. <form action='xxx.php' method='post'> <table> <tr> <th>Branch Id</th> <td><input id=branchId type=text
For example, consider this markup: <table> <tr> <td> <div id=d1> <div>222</div> <div>333</div> </div> </td>
I'm parsing JSON that is contained in an HTML element. Consider this markup: <div
Consider this simple markup: <body> <div style=border: 2px solid navy; position:absolute; width:100%; height:100%> </div>
Consider the following HTML markup. In most browsers that I have tested, the second
Consider a simple text markup language where _underscores denote italics_ and *astrisks denote bold*
Possible Duplicate: Is there a CSS parent selector? Consider this markup: <div> <div> <p
Consider the following JSF 2.x markup: <h:form id=form1> <h:inputText id=input value=#{testBacking.input}/> </h:form> <h:form id=form2>
I have this markup for my index.html <html> <head> <title>Jquery Ajax</title> <script src=jquery.js></script> <script>
Consider this scenario: <asp:CheckBoxList> in a master page. the goal is to have all

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.