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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:43:08+00:00 2026-06-14T04:43:08+00:00

html: <input list=items id=item> <datalist id=items> <option value=A item data-xyz = 1 > <option

  • 0

html:

<input list="items" id="item">

<datalist id="items">
  <option value="A item"  data-xyz = "1" >
  <option value="aa item" data-xyz = "2" >
  <option value="C item"  data-xyz = "3" >
  <option value="D item"  data-xyz = "4" >
  <option value="E item"  data-xyz = "5" >
</datalist> 

<input type="button" id="button" value="Get xyz" />

js:

$("#button").click(function(){
       alert($("#items option:selected").attr('data-xyz'));
});

link to jsbin

Query:

I just need to access the value of ‘data-xyz’ from selected datalist
option on click of “#button” or any event.

jQuery version: 1.7.2

Thanks.

  • 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-14T04:43:10+00:00Added an answer on June 14, 2026 at 4:43 am

    datalist is simply a storage for autocomplete. Since it could be used for multiple elemnts in page, it wil not have a selected property.

    You will need to locate the applicable option yourself such as the following

    $("#button").click(function() {
        var val = $('#item').val()
        var xyz = $('#items option').filter(function() {
            return this.value == val;
        }).data('xyz');
        /* if value doesn't match an option, xyz will be undefined*/
        var msg = xyz ? 'xyz=' + xyz : 'No Match';
        alert(msg)
    
    })
    

    DEMO: http://jsfiddle.net/shcRJ/

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

Sidebar

Related Questions

I have a list if items and on each item I have button. When
I have a form with different html input fields... 1) <input type=text> 2) <textarea></textarea>
I have a page with File html input field and a Submit button as
I want to use the placeholder attribute for HTML input[type=text] elements such that the
I've 2 asp listbox controls and an html input button, and using js i
Is there a simple way to upload a single file through HTML input type
I want to read the file path from html input type=file (the entry selected
From my research, I know that I cannot use HTML input file to get
I have a View that renders a list of items, and each item contains
I got a list of: public class Items { public String Nro_Item { get;

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.