jquery - Populate dropdown value looping thru a set of links -
i want loop thru a
's inside div , populate option value of select box above href
value of a
in order appears using jquery
this code
<div class="results_filter"> <label for="sort" class="dropdown_label">sort by:</label> <select name="sort" id="sort" class="custom_select"> <option value="">make</option> <option value="">year of manufature</option> <option value="">price</option> </select> <a href="/cars/index/sort:make_id/direction:asc">make</a><a href="/cars/index/sort:model_year/direction:asc">year of manufature</a><a href="/cars/index/sort:asking_price_from/direction:asc">price</a> </div>
i tried not working
$(document).ready(function () { $('div.results_filter > a').each(function (n) { $("#sort > options" + n).val($(this).text()); }); })
any appreciated. please don't ask me why awkward method. :)
you have create new option
element each 1 , append them select.
var sort = $("#sort"); $("div.results_filter > a").each(function() { var option = $("<option>").attr("value",$(this).attr("href")).text($(this).text()); sort.append(option); });
Comments
Post a Comment