0
Option tag doesn't require a closing tag ? Yes or no?
That was a question from html challenge . option from <datalist> doesn't need closing tag I.e <option value=""> where as option from <select> required it I.e <option value=""></option> .
4 ответов
+ 2
Optional. But depends on usage, you need to add.. See this
https://www.w3schools.com/tags/tag_option.asp
+ 2
Jayakrishna🇮🇳 optional I get it . that means it might be required or might be not. But thats a question from challenge which answer can be both , isnt it? It get me hard sometime
0
anjit pariyar oh. Answer is yes.
You can ingore closing tag of option when there are only option tags or no more elements, or next element is also option tag...
In data list, you have only option elements in side data list in sequence.. So you can ingore..
Like
<datalist id=" types ">
<option value="type1">
<option value="type2">
<option value="type">
...
<datalist/>
Where as in select tag, you have to give labels to options and it may contain other optgroup elements.. So you need to put end tag for option..
Ex:
<select groups="group1 or group2">
<optgroup label="group1">
<option value="v1"> label1 </option>
<option value="v2"> label2 </option>
</optgroup>
<optgroup label="group2">
<option value="v1">label1 </option>
<option value="v2">label2 </option>
</optgroup>
</select>