Spans in options

766 views
Skip to first unread message

Philip Thompson

unread,
Oct 5, 2009, 12:20:11 PM10/5/09
to clien...@googlegroups.com
Hi all. I know this isn't specifically a clientcide issue (or even a
mootools issue), but I can't access spans within select options.
Here's what I have:

<select name="hi" id="bye">
<option value="1"><span class="s1">A Span 1</span></option>
<option value="2"><span class="s1">A Span 2</span></option>
<option value="3"><span class="s1">A Span 3</span></option>
</select>

alert($('bye').getElements('span').length);

I would expect the alert to be '3', but it's 0. Is this a browser,
mootools or me issue? Or none of the above...?

Thanks,
~Philip

PS... I tried to access the mootools forum, but was having issues
logging in.

Zach Gambino

unread,
Oct 5, 2009, 4:02:43 PM10/5/09
to clien...@googlegroups.com
AFAIK, spans are not valid XHTML or even HTML markup. Firefox will
ignore spans inside of options elements thus making it impossible to
reach them.

Philip Thompson

unread,
Oct 5, 2009, 6:30:06 PM10/5/09
to clien...@googlegroups.com
According to W3C, the spans are alive and well.


However, they're not alive and well in "options." I ran the example below through the HTML validator and got these results:

----------------------
        #  Error  Line 12, Column 42: document type does not allow element "span" here
            <option value="1"><span class="s1">A Span 1</span></option>

        The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).

        One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).
----------------------

Well, now I know. Thanks for pushing me to look that up. ;-)

~Philip

Zach Gambino

unread,
Oct 5, 2009, 6:33:06 PM10/5/09
to clien...@googlegroups.com
Lol, sorry for the confusion, I was referring to spans inside of options. lol.
Of course spans alone are valid 8-)

Aaron Newton

unread,
Oct 5, 2009, 10:45:13 PM10/5/09
to clien...@googlegroups.com
option tags do not allow other tags within them (it's not valid html). firefox, for example, simply removes them from the DOM when it renders it. Put this html on a page and inspect it w/ firebug. you'll see there are no spans.

On Mon, Oct 5, 2009 at 9:20 AM, Philip Thompson <philth...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages