Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 28th, 2008, 12:15 PM
SuneR
Guest
 
Posts: n/a
Default Issue in FF: document.write a DIV (block level element) inside aLABEL tag

Hi,

I am having problems figuring out how to make Firefox behave, and
output the HTML I want it to output.

The thing I want done is actually quite simple. I have a <labeltag,
and inside it, I have a script tag, that document.write's some HTML.

Like this:

<label>
<script type="text/javascript">
document.write("<div>Test<\/div>");
</script>
</label>

In Internet Explorer, the result is this:

<label>
<script type="text/javascript">
document.write("<div>Test<\/div>");
</script>
<div>Test</div>
</label>

But in Firefox it is

<label>
<script type="text/javascript">
document.write("<div>Test<\/div>");
</script>
</label>
<div>Test</div>

In other words, the <divis added AFTER the closing </labeltag.

If I change the script to make a document.write("<span>Test<\/span>");
the output is ok in Firefox.

It seems that if you try to document.write a block level element
inside an inline element, Firefox moves it outside the inline element.

I have a stylesheet that makes the outputtet div inline, but Firefox
moves it no matter what.

I am sure this is behaviour as intented from Firefox, since this
happens in both FF2 and FF3, but what can I do to make it work?

Im thinking some sort of code to automatically append the <divto the
parent element. My problem here is, that I never really know what type
of parent element it is. And I cant just append it at the end because
my output might be in the middle of the parents innerHTML.

Any ideas? Tips? Thoughts?
  #2  
Old August 28th, 2008, 01:05 PM
pr
Guest
 
Posts: n/a
Default Re: Issue in FF: document.write a DIV (block level element) insidea LABEL tag

SuneR wrote:
Quote:
It seems that if you try to document.write a block level element
inside an inline element, Firefox moves it outside the inline element.
Very sensibly; a div inside a label would be invalid HTML. See <URL:
http://www.w3.org/TR/html401/interact/forms.html#edef-LABEL>.
Quote:
>
I have a stylesheet that makes the outputtet div inline, but Firefox
moves it no matter what.
The stylesheet makes no difference to whether your markup is valid. A
browser may cope with invalid markup in whatever way it sees fit.
Quote:
>
I am sure this is behaviour as intented from Firefox, since this
happens in both FF2 and FF3, but what can I do to make it work?
Define 'work'. If you want arbitrary elements inside other arbitrary
elements, use XML. If you want a web browser to display HTML then you
must use (real) HTML.
  #3  
Old August 28th, 2008, 02:05 PM
Richard Cornford
Guest
 
Posts: n/a
Default Re: Issue in FF: document.write a DIV (block level element) inside a LABEL tag

pr wrote:
Quote:
SuneR wrote:
Quote:
>It seems that if you try to document.write a block level element
>inside an inline element, Firefox moves it outside the inline
>element.
>
Very sensibly; a div inside a label would be invalid HTML. See
<URL: http://www.w3.org/TR/html401/interact/forms.html#edef-LABEL>.
>
Quote:
>>
>I have a stylesheet that makes the outputtet div inline, but
>Firefox moves it no matter what.
>
The stylesheet makes no difference to whether your markup is
valid.
True, but if the intent is to have the effect of a block element inside
an inline element then the stylesheet can act the other way around, and
display:block; an inline element (such as a SPAN). And if there is a
desire to have an inline element then there was no reason for using a
DIV in the first place.
Quote:
A browser may cope with invalid markup in whatever way it
sees fit.
<snip>

And each and every browsers may handle such mark-up in its own unique
way, as any specification for the standardised handling of invalid
mark-up would make no sense.

Richard.

  #4  
Old August 28th, 2008, 02:25 PM
SuneR
Guest
 
Posts: n/a
Default Re: Issue in FF: document.write a DIV (block level element) inside aLABEL tag

You are of course completely right, it makes perfect sense when you
put it that way :). When I had the issue, I focused more on the
"error" than on what is in fact the more correct way to handle the
markup.

Thanks for clearing it up for me.
  #5  
Old August 28th, 2008, 08:05 PM
dhtml
Guest
 
Posts: n/a
Default Re: Issue in FF: document.write a DIV (block level element) insidea LABEL tag

Richard Cornford wrote:
Quote:
pr wrote:
Quote:
>SuneR wrote:

Quote:
Quote:
>A browser may cope with invalid markup in whatever way it
>sees fit.
<snip>
>
And each and every browsers may handle such mark-up in its own unique
way, as any specification for the standardised handling of invalid
mark-up would make no sense.
>
Tell that to Ian Hickson.

HTML 5 defines not only quirks mode, but defines 3 modes:
http://www.whatwg.org/specs/web-apps...html#no-quirks

Garrett

Quote:
Richard.
  #6  
Old August 31st, 2008, 10:25 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: Issue in FF: document.write a DIV (block level element) insidea LABEL tag

Richard Cornford wrote:
Quote:
pr wrote:
Quote:
>SuneR wrote:
Quote:
>>It seems that if you try to document.write a block level element
>>inside an inline element, Firefox moves it outside the inline
>>element.
>Very sensibly; a div inside a label would be invalid HTML. See
><URL: http://www.w3.org/TR/html401/interact/forms.html#edef-LABEL>.
>>
Quote:
>>I have a stylesheet that makes the outputtet div inline, but
>>Firefox moves it no matter what.
>The stylesheet makes no difference to whether your markup is
>valid.
>
True, but if the intent is to have the effect of a block element inside
an inline element then the stylesheet can act the other way around, and
display:block; an inline element (such as a SPAN). And if there is a
desire to have an inline element then there was no reason for using a
DIV in the first place.
JFTR: A block-level element cannot be within an inline-level element. If it
is per markup, it is not Valid; if it is per CSS, the result is usually
design nonsense.

The only thing that could make sense is nesting one element that is
inline-level per default into one that is also inline-level per default
(which is usually allowed), and format the former element display:block
with CSS to hide it by default and show it on event. For example,
accessible tooltips (which will be featured by the next release of the
ECMAScript Support Matrix) can be created this way.


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles