선택 목록으로 변환해야하는 모든 UL LI 블록에 함수를 쓰는 대신 한 번만 함수를 사용하려고합니다. 당신은 .appendTo
로 엉망jQuery를보다 구체적으로 만들려면 어떻게해야합니까?
$('.filterSection').each(function(){
$('<select class="locationFilterSelect" />').appendTo(this);
//Create Default option "Select One"
$("<option />", {
"selected": "selected",
"value" : "",
"text" : "Select One"
}).appendTo('select', this);
// Populate dropdown with menu items
$('li', this).each(function() {
var el = $(this);
$("<option />", {
"text" : el.text()
}).appendTo('select', this);
});
});