File tree Expand file tree Collapse file tree 1 file changed +12
-13
lines changed
files/en-us/web/api/htmloptionelement/option Expand file tree Collapse file tree 1 file changed +12
-13
lines changed Original file line number Diff line number Diff line change @@ -65,15 +65,11 @@ options.forEach((element, key) => {
6565
6666### Append options with different parameters
6767
68- ``` js
69- /* assuming we have the following HTML
70- <select id="s">
71- <option>First</option>
72- <option>Second</option>
73- <option>Third</option>
74- </select>
75- */
68+ ``` html
69+ <select id =" s" ></select >
70+ ```
7671
72+ ``` js
7773const s = document .getElementById (" s" );
7874const options = [" zero" , " one" , " two" ];
7975
@@ -85,17 +81,20 @@ options.forEach((element, key) => {
8581 s[key] = new Option (element, s .options .length , true , false ); // Will add the "selected" attribute
8682 }
8783 if (element === " two" ) {
88- s[key] = new Option (element, s .options .length , false , true ); // Just will be selected in " view"
84+ s[key] = new Option (element, s .options .length , false , true ); // Will actually be selected in the view
8985 }
9086});
87+ ```
9188
92- /* Result
89+ Result:
90+
91+ ``` html
9392<select id =" s" >
9493 <option value =" 0" >zero</option >
95- <option value="1" selected="">one</option>
96- <option value="2">two</option> // User will see this as 'selected'
94+ <option value =" 1" selected >one</option >
95+ <option value =" 2" >two</option >
96+ <!-- User will see two as 'selected' -->
9797</select >
98- */
9998```
10099
101100## Specifications
You can’t perform that action at this time.
0 commit comments