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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -