Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #23471
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: JavaScript in a PRE element of an HTML document |
| Date | 2014-03-09 07:01 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <lfgsk3$hlv$1@dont-email.me> (permalink) |
| References | <JavaScript-20140308234930@ram.dialup.fu-berlin.de> |
2014-03-09 1:15, Stefan Ram wrote: > Is it alright to have a script in <code><pre>...</pre></code> > as in the following text that is intended to be an HTML5 document? Depends on your definition for "alright". You can put a <script> element inside a <pre> element and add content there with document.writeln(). It has a defined effect. But it's not regarded as good coding style due to various pitfalls, which may become a problem in real life - and your example is probably not quite as complex as the real case would be. Nesting <pre> inside <code> is invalid by any HTML spec. Browsers seems to construct the DOM the way we might naively expect, but things won't work normally, as you can see e.g. if you try to style the <code> element. You can nest them the other way around. On the other hand, the <code> element would be rather useless here, even if the content is actually computer code. The <code> markup does not have much effect beyond setting font family to monospace, and <pre> already does that here. > <!DOCTYPE HTML><html><head><title>T</title><meta charset="UTF-8"></head><body><code><pre><script> > var a = 5; > document.writeln( a + 1 ); > document.writeln( a ); > </script></pre></code></body> > > Anything else that is wrong with the above page (except for > that the first line might be deemed too long)? There is no limit on line length in HTML. People who read the code might not like long lines. The most obvious thing with the page is that it makes no sense. I suppose the intended real use case would have a loop that generates lines of text. Whether that makes sense depends on the content. But assuming it makes sense to do so client-side, it would be more suitable, and not really more difficult, to add the content by appending to the value of the innerHTML property. -- Yucca, http://www.cs.tut.fi/~jkorpela/
Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread
Re: JavaScript in a PRE element of an HTML document "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-03-09 07:01 +0200
Re: JavaScript in a PRE element of an HTML document "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-03-09 17:05 +0200
Re: JavaScript in a PRE element of an HTML document Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-09 17:15 +0100
Re: JavaScript in a PRE element of an HTML document "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-03-09 19:25 +0200
Re: JavaScript in a PRE element of an HTML document "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-09 19:44 +0100
Re: JavaScript in a PRE element of an HTML document Dr J R Stockton <reply1400@merlyn.demon.co.uk.invalid> - 2014-03-10 18:01 +0000
Re: JavaScript in a PRE element of an HTML document "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-03-11 09:59 +0100
Re: JavaScript in a PRE element of an HTML document Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-03-09 16:54 +0100
Re: JavaScript in a PRE element of an HTML document Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-03-09 16:30 +0000
Re: JavaScript in a PRE element of an HTML document Denis McMahon <denismfmcmahon@gmail.com> - 2014-03-09 22:16 +0000
Re: JavaScript in a PRE element of an HTML document "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2014-03-10 07:30 +0200
csiph-web