1717 < meta property ="og:site_name " content ="jQuery Selectric ">
1818 < meta property ="og:image " content ="http://lcdsantos.github.io/jQuery-Selectric/share.jpg ">
1919
20- < link rel ="stylesheet " id ="theme " href ="themes/default/ selectric.css ">
20+ < link rel ="stylesheet " id ="theme " href ="selectric.css ">
2121 < style id ="template " style ="display: none; "> </ style >
2222</ head >
2323< body >
@@ -58,8 +58,72 @@ <h3>Basic usage</h3>
5858 </ div >
5959
6060 < div class ="code ">
61- < pre > < code class ="language-javascript "> $(function(){
62- $('select').selectric();
61+ < pre > < code class ="language-javascript "> $('select').selectric();</ code > </ pre >
62+ </ div >
63+ </ div >
64+
65+ < div class ="demo ">
66+ < h3 > Get selected option value</ h3 >
67+
68+ < div class ="view ">
69+ < select id ="get_value ">
70+ < option value ="strawberries "> Strawberries</ option >
71+ < option value ="mango "> Mango</ option >
72+ < option value ="bananas "> Bananas</ option >
73+ < option value ="watermelon "> Watermelon</ option >
74+ < option value ="apples "> Apples</ option >
75+ < option value ="grapes "> Grapes</ option >
76+ < option value ="oranges "> Oranges</ option >
77+ < option value ="pineapple "> Pineapple</ option >
78+ < option value ="peaches "> Peaches</ option >
79+ < option value ="cherries "> Cherries</ option >
80+ </ select >
81+
82+ < p id ="select_value "> Current value: < strong > </ strong > </ p >
83+ </ div >
84+
85+ < div class ="code ">
86+ < pre > < code class ="language-javascript "> // Cache the target element
87+ var $selectValue = $('#select_value').find('strong');
88+
89+ // Get initial value
90+ $selectValue.text($('#get_value').val());
91+
92+ // Initialize Selectric and bind to 'change' event
93+ $('#get_value').selectric().on('change', function() {
94+ $selectValue.text($(this).val());
95+ });</ code > </ pre >
96+ </ div >
97+ </ div >
98+
99+ < div class ="demo ">
100+ < h3 > Set value</ h3 >
101+
102+ < div class ="view ">
103+ < select id ="set_value ">
104+ < option value ="0 "> First option</ option >
105+ < option value ="1 "> Second option</ option >
106+ < option value ="2 "> Third option</ option >
107+ </ select >
108+
109+ < p > < button id ="set_first_option "> Select 1st option</ button > </ p >
110+ < p > < button id ="set_second_option "> Select 2nd option</ button > </ p >
111+ < p > < button id ="set_third_option "> Select 3rd option</ button > </ p >
112+ </ div >
113+
114+ < div class ="code ">
115+ < pre > < code class ="language-javascript "> $('#set_value').selectric();
116+
117+ $('#set_first_option').on('click', function() {
118+ $('#set_value').prop('selectedIndex', 0).selectric('refresh');
119+ });
120+
121+ $('#set_second_option').on('click', function() {
122+ $('#set_value').prop('selectedIndex', 1).selectric('refresh');
123+ });
124+
125+ $('#set_third_option').on('click', function() {
126+ $('#set_value').prop('selectedIndex', 2).selectric('refresh');
63127});</ code > </ pre >
64128 </ div >
65129 </ div >
@@ -81,26 +145,24 @@ <h3>Change options on the fly</h3>
81145 < option value ="cherries "> Cherries</ option >
82146 </ select >
83147
84- < input type ="text " id ="add_val " name ="add_val ">
85- < button id ="bt_add_val "> Add value</ button >
148+ < p >
149+ < input type ="text " id ="add_val " name ="add_val ">
150+ < button id ="bt_add_val "> Add value</ button >
151+ </ p >
86152 </ div >
87153
88154 < div class ="code ">
89- < pre > < code class ="language-javascript "> $(function(){
90- $('#dynamic').selectric();
91-
92- $('#bt_add_val').click(function(e){
93- e.preventDefault();
155+ < pre > < code class ="language-javascript "> $('#dynamic').selectric();
94156
95- // Store the value in a variable
96- var value = $('#add_val').val();
157+ $('#bt_add_val').click(function() {
158+ // Store the value in a variable
159+ var value = $('#add_val').val();
97160
98- // Append to original select
99- $('#dynamic').append('<option>' + (value ? value : 'Empty') + '</option>');
161+ // Append to original select
162+ $('#dynamic').append('<option>' + (value ? value : 'Empty') + '</option>');
100163
101- // Refresh Selectric
102- $('#dynamic').selectric('refresh');
103- });
164+ // Refresh Selectric
165+ $('#dynamic').selectric('refresh');
104166});</ code > </ pre >
105167 </ div >
106168 </ div >
@@ -126,10 +188,10 @@ <h3>Callbacks</h3>
126188 < div class ="code ">
127189 < pre > < code class ="language-javascript "> // With events
128190$('#callbacks')
129- .on('selectric-before-open', function(){
191+ .on('selectric-before-open', function() {
130192 alert('Before open');
131193 })
132- .on('selectric-before-close', function(){
194+ .on('selectric-before-close', function() {
133195 alert('Before close');
134196 })
135197 // You can bind to change event on original element
@@ -160,7 +222,7 @@ <h3>Populate via ajax request</h3>
160222 </ div >
161223
162224 < div class ="code ">
163- < pre > < code class ="language-javascript "> $.get('ajax.html', function(data){
225+ < pre > < code class ="language-javascript "> $.get('ajax.html', function(data) {
164226 $('#ajax').append(data).selectric();
165227});</ code > </ pre >
166228 < br >
@@ -172,7 +234,7 @@ <h3>Populate via ajax request</h3>
172234 < h3 > Custom markup for items box</ h3 >
173235
174236 < div class ="view ">
175- < select class ="customOptions ">
237+ < select class ="custom-options ">
176238 < option value =""> Select with icons</ option >
177239 < option value ="firefox "> Firefox</ option >
178240 < option value ="chrome "> Chrome</ option >
@@ -183,12 +245,10 @@ <h3>Custom markup for items box</h3>
183245 </ div >
184246
185247 < div class ="code ">
186- < pre > < code class ="language-javascript "> $(function(){
187- $('.customOptions').selectric({
188- optionsItemBuilder: function(itemData, element, index){
189- return element.val().length ? '<span class="ico ico-' + element.val() + '"></span>' + itemData.text : itemData.text;
190- }
191- });
248+ < pre > < code class ="language-javascript "> $('.custom-options').selectric({
249+ optionsItemBuilder: function(itemData, element, index) {
250+ return element.val().length ? '<span class="ico ico-' + element.val() + '"></span>' + itemData.text : itemData.text;
251+ }
192252});</ code > </ pre >
193253 < br >
194254 < pre data-src ="customoptions.css "> </ pre >
0 commit comments