Forum Moderators: open

Message Too Old, No Replies

Closing Options

Question about Closing the Option Tag

         

yintercept

10:34 pm on Apr 7, 2007 (gmt 0)

10+ Year Member



The closing option tag used to be optional. In XHTML, we are supposed to close everything.

I am using the option tag a lot on a site. I noticed that I could reduce about 3% of a project's bandwidth by nixing the close option tag. Is it considered okay to close the option tag inline.

This is what I would like to do

<option value="1" />One
<option value="2" />Two
<option value="3" />Three

This is what I currently do:

<option value="1" />One</option>
<option value="2" />Two</option>
<option value="3" />Three</option>

I tested the idea on different browsers and it displayed okay.

encyclo

4:04 pm on Apr 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<option value="1" />One</option>

The trailing slash in the above example is incorrect because it would close the

option
element before the contents.

You can't rely on using XML syntax unless you are using XHTML served as XML rather than HTML, and in that case your page wouldn't work in Internet Explorer.

You have two options: either to use the syntax

<option value="1">One</option>
and continue using an XHTML doctype, or you can switch to HTML 4.01 Transitional (as XHTML as HTML offers no advantages) and drop the closing tag.

Fotiman

4:26 pm on Apr 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You might also want to read the discussion Why most of us should NOT use XHTML [webmasterworld.com].

abhishekkaushik

1:56 am on Apr 13, 2007 (gmt 0)

10+ Year Member



Sometimes an incorrect tag can display well this is the property of HTML, wrong is wrong I don't know is it good to do this a better idea could be you validate your page with W3C if they says it's OK then no problem.