Get the data attribute element from datalist options

We can use a datalist instead of select option to add a dropdown to an input element. Datalist is commonly used when we want type in the input element and select from the dropdown based on that. We can use that in the site builder also.In datalist we can get the value and text of the selected option.But we cannot get any other data added as attribute in them.
To get the data other than value we can add them in data attribute.For eg:data-id,data-xyz like that.
To retrieve the data attribute value in the site builder code we can use the code below.


First we need to take the value then on the basis of that need to get the data value.

var valueadded= $(‘#quickaddSearch’).val();
var inputQtyRefId = $(‘#quick_search [value=”‘ + valueadded+ ‘”]’).data(‘xyz’);
The inputQtyRefId will contain the data-xyz value.

Leave a comment

Your email address will not be published. Required fields are marked *