forked from dikshantmali/Hacktoberfest2020-HTML-CSS-WEB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
45 lines (38 loc) · 1.17 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
$('.select').each(function () {
var $this = $(this),
numberOfOptions = $(this).children('div').length;
$this.addClass('select-hidden');
$this.wrap('<div class="select"></div>');
$this.after('<div class="select-styled"></div>');
var $styledSelect = $this.next('div.select-styled');
$styledSelect.text($this.children('div').eq(0).text());
var $list = $('<ul />', {
class: 'select-options',
}).insertAfter($styledSelect);
for (var i = 0; i < numberOfOptions; i++) {
$('<li />', {
text: $this.children('div').eq(i).text(),
rel: $this.children('div').eq(i).val(),
}).appendTo($list);
}
var $listItems = $list.children('li');
$styledSelect.click(function (e) {
e.stopPropagation();
$('div.select-styled.active')
.not(this)
.each(function () {
$(this).removeClass('active').next('ul.select-options').hide();
});
$(this).toggleClass('active').next('ul.select-options').toggle();
});
$listItems.click(function (e) {
e.stopPropagation();
$styledSelect.text($(this).text()).removeClass('active');
$this.val($(this)[0].textContent);
$list.hide();
});
$(document).click(function () {
$styledSelect.removeClass('active');
$list.hide();
});
});