Answer the question
In order to leave comments, you need to log in
Autocomplete: how to add data attribute to li tags in SERP?
Good day.
Actually the question is in the title.
I want to add the data-value="region-value" attribute to the li tag,
so that I can later get the value of the region and open it on Yandex maps.:
I tried to do it a little differently, but it doesn't work:
var options = $('#regionsList option');
var array_option_v2 = new Array();
jQuery.each(options, function(index, value) {
var option_value = jQuery(value).val();
var option_name = jQuery(value).text();
array_option_v2.push('<span data-option-value="' + option_value + '">' + option_name + '</span');
})
$("#input-region-name").autocomplete({
source: array_option_v2 ,
minLength: 2
});
Answer the question
In order to leave comments, you need to log in
Maybe so
var options = $('#regionsList option');
var array_option_v2 = new Array();
jQuery.each(options, function(index, value) {
var span = document.createElement('span');
jQuery(span).data('option-value',jQuery(value).val());
jQuery(span).html(jQuery(value).text())
array_option_v2.push(span);
})
$("#input-region-name").autocomplete({
source: array_option_v2 ,
minLength: 2
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question