So. We have this script for turning the drop-down list into a bulleted one.
jQuery.fn.selecttolist = function(options) { return this.each(function() { var select = $(this); select.hide(); var buttonsHtml = $('<div class="options-cont"></div>'); var selectIndex = 0; var addOptGroup = function(optGroup) { if (optGroup.attr('label')) { buttonsHtml.append('<strong>' + optGroup.attr('label') + '</strong>'); } var ulHtml = $('<ul class="select-buttons">'); optGroup.children('option').each(function() { var liHtml = $('<li></li>'); if ($(this).attr('disabled') || select.attr('disabled')) { liHtml.addClass('disabled'); liHtml.append('<span>' + $(this).html() + '</span>'); } else { liHtml.append('<a href="javascript://" data-select-index="' + selectIndex + '">' + $(this).html() + '</a>'); } if ((!options || !options.noDefault) && select.attr("selectedIndex") == selectIndex) { liHtml.children('a, span').addClass('picked'); } ulHtml.append(liHtml); selectIndex++; }); buttonsHtml.append(ulHtml); } var optGroups = select.children('optgroup'); if (optGroups.length == 0) { addOptGroup(select); } else { optGroups.each(function() { addOptGroup($(this)); }); } select.after(buttonsHtml); buttonsHtml.find('a').click(function(e) { e.preventDefault(); buttonsHtml.find('a, span').removeClass('picked'); $(this).addClass('picked'); $(select.find('option')[$(this).attr('data-select-index')]).attr('selected', 'selected'); select.trigger('change'); }); }); }; $('select').selecttolist(); $('li:first-child').children().addClass('picked'); body, ul { margin: 0; padding: 0; } ul { display: flex; flex-wrap: wrap; list-style: none; } a { display: block; color: #333; text-decoration: none; padding: 10px; } div { padding: 30px; } a:hover, .picked { background: #eee; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select class="shop-options-s " id="id-oval" onchange="changeOptions('/shop/desc/krasula', 'id', '36', this)"> <option value="0">Простое значение</option> <option value="1">Простое значение 2</option> <option value="2">#CC0000</option> <option value="3">#336600</option> <option value="4">Белый</option> <option value="5">Черный</option> <option value="6">Красный</option> <option value="7">Серый</option> <option value="8">Полоска</option> <option value="9">Кружок</option> </select> The question is this. Is it possible to attach to this solution the check of the contents of the options of the selector and the filling of the background of the blocks with the value found. I try 2 options.
1st. When checking the contents of an option on the first character and number of characters. For example, in this form of the option: <option value="1">#336600</option> , if the first character is # , and all characters are 7 , then we insert this hash into the background link of the created drop-down list.
2nd. Create a file with the following values:
jQuery.fn.selecttolist.init({ colors: { 'Черный': '#000000', 'Красный': '#FF0000', 'Белый': '#FFFFFF', 'Серый': '#CCCCCC', 'Полоска': 'url(/images/poloska.png) no-repeat center center', 'Кружок': 'url(/images/krug.png) no-repeat center center' }, hideColorsTitle: true }); And if the contents of the option coincide with the specified values from the list, substitute this value in the background reference of the created bulleted list.
What I would like to receive:
I would be grateful for any help because he himself was already tortured with this task.
