change each option value javascript/jQuery -
i need grab each select
option
value in dropdown , use them generate image attribute each option. example, if value of option
first image
data-img-src
value path image folder/first-image.png
the below code works fine generates data-img-src
first option
only. need return data-img-src
each option in dropdown. how can this?
jquery(document).ready(function($){ $(".selector option").attr('data-img-src', function() { var file = this.value + '.png'; var img = file.tolowercase().replace(/ /g, '-'); var path = 'path folder'; return path + img }); });
thanks in advance , have day.
you can use each() iterate , update attribute of options.
$(".selector option").each(function(){ $(this).attr('data-img-src', function() { var file = this.value + '.png'; var img = file.tolowercase().replace(/ /g, '-'); var path = 'path folder'; return path+img }); });
Comments
Post a Comment