Internet image by Leticia Wilson from Fotolia.com
HTML consists of statements that define a Web page's elements, controls and appearance. You can place text anywhere inside the body of an HTML document. Unfortunately, browsers remove extra spacing between words in a text string. This increases the time it takes to format some elements such as the HTML marquee. A marquee displays scrolling text that moves across a Web page. To add spaces to text in a marquee, use JavaScript to replace regular spaces with special characters that the browser will not remove.
Open Notepad. Paste this HTML code into an empty document:
This creates a Marquee that contains no text.
Add the following JavaScript function after the "
function set Marquee() {
This function sets the marquee text. The variable "originalText" holds the text string that you want to appear in the marquee. In this example, that text is "Marquee String Text." Add as many spaces as you like between the words or characters. "MarqueeID" holds the ID of the marquee. The "replace" method replaces the blanks in the text string with the special HTML character stored in "blankCharacter." The last statement adds the modified text to the marquee object.
Add this JavaScript code after the previous code:
This calls the set Marquee function after the Web page loads.
Save the Notepad file with an .html extension. For example, if you want to name the file "Marquee Test," save it as "Marquee Test.html."
Open the file in your browser to verify that spaces exist between the words in the marquee's text.
Most recent
- Note that the "<marquee>" tag in the body of the HTML has an id of "Marquee1." Name the ID anything you like. It must, however, match the value that you set for MarqueeID in the JavaScript function.
- Internet image by Leticia Wilson from Fotolia.com