JavaScipt
~~~~~~~
<script type="text/javascript">
name = new String("My Name");
document.write("<H4>Author: </H4>" + name);
</script>
I would like the word 'Author:' to be in 4th level heading and the name
variable value to be displayed in regular font, I get that but in two
lines. What can I do to get the browser to display the two values in
one line?
TIA.
Vic Sowers - 31 Mar 2006 00:04 GMT
> JavaScipt
> ~~~~~~~
[quoted text clipped - 7 lines]
> lines. What can I do to get the browser to display the two values in
> one line?
The header elements are, by default, defined as 'block' elements, which
means they insert a line break following the element, so it's best not to
use them in this context.
Instead use a font control element like:
document.write("<strong>Author: </strong>" + name);
or
document.write("<span style='font:bold 12pt Arial;'">Author: </span>" +
name);
If you absolutely must use the <H4> element, try:
document.write("<H4 style='display:inline;'">Author: </H4>" + name);
Thomas 'PointedEars' Lahn - 31 Mar 2006 00:32 GMT
> JavaScipt
What?
> ~~~~~~~
> <script type="text/javascript">
> name = new String("My Name");
You do not have to create a String object for this. A string value will do
just fine. Using `name' undeclared is overwriting the `name' property of
the global Window object in known HTML environments. Declaring `name'
perhaps disables it. Do not use `name' in global context.
var ref = "My Name";
> document.write("<H4>Author: </H4>" + name);
Must be
document.write("<H4>Author: <\/H4>" + ref);
Should be
document.write("<h4>Author: <\/h4>" + ref);
> </script>
>
> I would like the word 'Author:' to be in 4th level heading and the name
> variable value to be displayed in regular font, I get that but in two
> lines. What can I do to get the browser to display the two values in
> one line?
This has nothing to do with programming in an ECMAScript-conforming language
(which is on-topic here). Try CSS, and do not add whitespace at the end of
the element content:
<h4 style="display:inline">Author:</h4>
Never ever use a hX element if it is not a heading, just because it looks
nice on your browser! Use font-formatting instead.
<URL:http://www.w3.org/QA/Tips/headings>
PointedEars
Hal Rosser - 31 Mar 2006 01:53 GMT
> JavaScipt
> ~~~~~~~
[quoted text clipped - 7 lines]
> lines. What can I do to get the browser to display the two values in
> one line?
The h4 tag will show on its own line by default.
Why not use <p> and <span> tags with style attributes to get it to look the
way you want.