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

The Archive Base Latest Questions

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

Given this HTML code: <select id=menu> <option>hi</option> <option>bye</option> </select> This jQuery code: $(#menu option).first().attr(value)

  • 0

Given this HTML code:

<select id="menu">
    <option>hi</option>
    <option>bye</option>
</select>

This jQuery code:

$("#menu option").first().attr("value")

returns hi, even though there is no value attribute on the first option in the menu.

If the <option> has a value attribute, the value attribute is returned, as expected.

How can I have the return value of the above code be undefined / something else I can identify? Or could I check if the value attribute is set, and only run the above code if it isn’t?

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

    Use the :not([attr]) selector:

    $("#menu option:not([value])");
    

    http://jsfiddle.net/userdude/NQm54/

    I also verified that after changing, the [value] still reports as unset, so you continue to receive the same two elements without the value attribute.

    $('#menu').change(function(){
      console.log($(this).val());
      console.log($("#menu option:not([value])"));
    });
    

    http://jsfiddle.net/userdude/NQm54/2/

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

Sidebar

Related Questions

Given this html: code I'd like a selection of b in Select d1 to
Ok, here's what I'm trying to do... given this razor code @using(Html.WriteLater()) { output
I pasted the code given in this link to a file called md5.js. http://www.webtoolkit.info/javascript-md5.html
Given this HTML: <div class=OpenIDSelector>some text</div> Why does this JQuery selector match it on
Given this HTML: <form id=formx> <input type=text value= /> </form> And this JavaScript: $(function()
Given this code snippet, I know that if the user selects 25c the value
I'm trying to use the jQuery UI to style my HTML select menu but
I'm developing a little jQuery selector game. Essentially, you're given some HTML code, and
Given this html: <div class=nation> <a href=library.php?type=nation&amp;id=America> <div class=nation-image> <img src=nations/America.png alt=snip /> </div>
Given this HTML: <div id=foo> <input type=button class=foo abtn_1> <input type=button class=joe bbtn_2> <input

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.