String HTML Wrappers
Here is a list of the methods that return a
copy of the string wrapped inside an appropriate HTML tag.
Method
|
Description
|
|
anchor()
|
Creates an HTML anchor that is used as a
hypertext
|
|
target.
|
||
big()
|
Creates a string to be displayed in a big
font as if it
|
|
were in a <big> tag.
|
||
blink()
|
Creates a string to blink as if it were in a
<blink> tag.
|
|
bold()
|
Creates a string to be displayed as bold as
if it were in a
|
|
<b> tag.
|
||
fixed()
|
Causes a string to be displayed in
fixed-pitch font as if
|
|
it were in a <tt> tag
|
||
fontcolor()
|
Causes a string to be displayed in the
specified color as
|
|
if it were in a <font
color="color"> tag.
|
||
fontsize()
|
Causes a string to be displayed in the
specified font size
|
|
as if it were in a <font
size="size"> tag.
|
||
italics()
|
Causes a string to be italic, as if it were
in an <i> tag.
|
|
link()
|
Creates an HTML hypertext link that requests
another
|
|
URL.
|
||
small()
|
Causes a string to be displayed in a small
font, as if it
|
|
were in a <small> tag.
|
||
strike()
|
Causes a string to be displayed as struck-out
text, as if
|
|
it were in a <strike> tag.
|
||
sub()
|
Causes a string to be displayed as a
subscript, as if it
|
|
|
||
were in a <sub> tag
|
||
sup()
|
Causes a string to be displayed as a
superscript, as if it
|
|
were in a <sup> tag
|
||
In the following
sections, we will have a few examples to demonstrate the usage of string HTML
wrappers.
anchor()
This method creates an HTML anchor that is used as a hypertext target.
Syntax
Its syntax is as follows:
string.anchor( anchorname )
Attribute details
anchorname: Defines a name for the anchor.
Return Value
Returns the string having the anchor tag.
Example
Try the following example.
<html>
<head>
<title>JavaScript String anchor()
Method</title>
</head>
<body>
<script
type="text/javascript">
var str = new String("Hello
world");
alert (str.anchor( "myanchor" ));
</script>
</body>
</html>
Output
<a name="myanchor">Hello
world</a>
big()
This method causes a string to be displayed in
a big font as if it were in a BIG tag.
Syntax
The syntax to use big() is as follows:
string.big()
Return Value
Returns the string having <big>
tag.
Example
Try the following example.
<html>
<head>
<title>JavaScript String big() Method</title>
</head>
<body>
<script
type="text/javascript">
var str = new String("Hello
world");
alert(str.big());
</script>
</body>
</html>
Output
<big>Hello world</big>
blink ()
This method causes a string to blink as if it were in a BLINK tag.
Syntax
The syntax for blink() method is as follows:
string.blink( )
Return Value
Returns the string having <blink>
tag.
Example
Try the following example.
<html>
<head>
<title>JavaScript String blink()
Method</title>
</head>
<body>
<script
type="text/javascript">
var str = new String("Hello
world");
alert(str.blink());
</script>
</body>
</html>
Output
<blink>Hello world</blink>
bold ()
This method causes a string to be displayed as bold as if it were in a
<b> tag.
Syntax
The syntax for bold() method is as follows:
string.bold( )
Return Value
Returns the string having <bold>
tag.
Example
Try the following example.
<html>
<head>
<title>JavaScript String bold() Method</title>
</head>
<body>
<script
type="text/javascript">
var str = new String("Hello
world");
alert(str.bold());
</script>
</body>
</html>
Output
<b>Hello world</b>
fixed ()
This method causes a string to be displayed in
fixed-pitch font as if it were in a <tt> tag.
Syntax
Its syntax is as follows:
string.fixed( )
Return Value
Returns the string having <tt>
tag.
Example
Try the following example.
<html>
<head>
<title>JavaScript String fixed()
Method</title>
</head>
<body>
<script
type="text/javascript">
var str = new String("Hello
world");
alert(str.fixed());
</script>
</body>
</html>
Output
<tt>Hello world</tt>
fontColor ()
This method causes a string to be displayed in
the specified color as if it were in a <font
color="color"> tag.
Syntax
Its syntax is as follows:
string.fontColor( color)
Attribute Details
color: A string expressing
the color as a hexadecimal RGB triplet or as a string literal.
Return Value
Returns the string with <font color="color"> tag.
Example
Try the following example.
<html>
<head>
<title>JavaScript String fontcolor()
Method</title>
</head>
<body>
<script
type="text/javascript">
var str = new String("Hello
world");
alert(str.fontcolor( "red" ));
</script>
</body>
</html>
Output
<font color="red">Hello
world</font>
0 comments:
Post a Comment