We now have a youtube channel. Subscribe!

How to implement JavaScript String Html Wrappers?



Hello guys, morning to you all from this end. I want to welcome you all to my new tutorial post on JavaScript. In this tutorial am going to be rounding up with JavaScript String object. In the previous tutorials, I already listed out the various String HTML Wrappers we have on JavaScript without explaining them properly with examples.

So now am going to be using series of examples to explain these String HTML Wrappers so you guys can have a better knowledge of how you can implement them in your programs. So now am going to be taking them one after the other, feel free to ask your questions via the comment box below.


String - anchor() Method

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 below for better understanding.

<html>
     <head>
          <title>JavaScript String anchor() Method</title>    
     </head>

     <body>
          <script  type = "text/Javascript">
               var  str = new String("Hello World");
               document.write(str.anchor( "myanchor" ) );
          </script>
     </body>
</html>

Output

Below is the output of the above example.

<a   name = "myanchor">Hello World</a>

You can also check out our tutorial post on: Learning JavaScript Number Object with examples

String - big() Method

This method causes a string to be displayed in a big font as if it were in a BIG tag.

Syntax

Its syntax is as follows:

string.big( )

Return Value

Returns the string having <big> tag.

Example

Try the following example below for better understanding.

<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

Below is the output of the above example.

<big>Hello World</big>



String - blink() Method

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 below for better understanding.

<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

Below is the output of the above example.

<blink>Hello World</blink>

You can also read our tutorial post on: Variable

String - bold() Method

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 below for better understanding.

<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

Below is the output of the above example.

<b>Hello World</b>

String - fixed() Method

This method causes a string to be displayed in fixed-pitch font as if it were in a <tt> tag.

Syntax

The syntax for fixed() method is as follows:

string.fixed( )

Return Value

Returns the string having <tt> tag.

Example

Try the following example below for better understanding.

<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

Below is the output of the above example.

<tt>Hello World</tt>

You can also check out one of our tutorials on: Introduction to Python Programming


String - fontcolor() Method

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 below for better understanding.

<html>
     <head>
          <title>JavaScript String fontcolor() Method</title>    
     </head>

     <body>
          <script  type = "text/Javascript">
               var  str = new String("Hello World");
               document.write(str.fontcolor( "black" ) );
          </script>
     </body>
</html>

Output

Below is the output of the above example.

<font color = "black">Hello World</font>


String - fontsize() Method

This method causes a string to be displayed in the specified size as if it were in a <font size = "size"> tag.

Syntax

Its syntax is as follows:

string.fontsize( size )

Attribute Details

size - An integer between 1 and 7, a string representing a signed integer between 1 and 7.

Return Value

Returns the string with <font size ="size"> tag.

Example

Try the following example below for better understanding.

<html>
     <head>
          <title>JavaScript String fontsize() Method</title>    
     </head>

     <body>
          <script  type = "text/Javascript">
               var  str = new String("Hello World");
               document.write(str.fontsize(  7  ) );
          </script>
     </body>
</html>

Output

Below is the output of the above example.

<font size = "7">Hello World</font>

Feel free to check out our tutorial post on: Python on Window

String - italics() Method

This method causes a string to be italic, as if it were in an <i> tag.

Syntax

The syntax for italics() method is as follows:

string.italics( )

Return Value

Returns the string having <i> tag.

Example

Try the following example below for better understanding.

<html>
     <head>
          <title>JavaScript String italics() Method</title>    
     </head>

     <body>
          <script  type = "text/Javascript">
               var  str = new String("Hello World");
               alert (str.italics(  ) );
          </script>
     </body>
</html>

Output

Below is the output of the above example.

<i>Hello World</i>

You can also read our tutorial post on: JavaScript Syntax


String - link() Method

This method creates an HTML hypertext link that requests another URL.

Syntax

Its syntax is as follows:

string.link( hrefname )

Attribute Details

hrefname - Any string that specifies the HREF of the A tag; it should be a valid URL.

Return Value

Returns the string with <a> tag.

Example

Try the following example below for better understanding.

<html>
     <head>
          <title>JavaScript String link() Method</title>    
     </head>

     <body>
          <script  type = "text/Javascript">
               var  str = new String("Hello World");
               var  URL = "https://webdesigntutorialz.blogspot.com";       
               document.write(str.link(  URL  ) );
          </script>
     </body>
</html>

Output

Below is the output of the above example.

<a  href = "https://www.webdesigntutorialz.com">Hello World</a>      

String - small() Method

This method causes a string to be displayed in a small font, as if it were in a <small> tag.

Syntax

The syntax for small() method is as follows:

string.small( )

Return Value

Returns the string having <small> tag.

Example

Try the following example below for better understanding.

<html>
     <head>
          <title>JavaScript String small() Method</title>    
     </head>

     <body>
          <script  type = "text/Javascript">
               var  str = new String("Hello World");
               alert (str.small(  ) );
          </script>
     </body>
</html>

Output

Below is the output of the above example.

<small>Hello World</small>

You can also check out our tutorial post on: How to implement JavaScript for....in loop with examples


String - strike() Method

This method causes a string to be displayed as struck-out text, as if it were in a <strike> tag.

Syntax

The syntax for strike() method is as follows:

string.strike( )

Return Value

Returns the string having <strike> tag.

Example

Try the following example below for better understanding.

<html>
     <head>
          <title>JavaScript String strike() Method</title>    
     </head>

     <body>
          <script  type = "text/Javascript">
               var  str = new String("Hello World");
               alert (str.strike(  ) );
          </script>
     </body>
</html>

Output

Below is the output of the above example.

<strike>Hello World</strike>

String - sub() Method

This method causes a string to be displayed as a subscript, as if it were in a <sub> tag.

Syntax

The syntax for sub() method is as follows:

string.sub( )

Return Value

Returns the string having <sub> tag.

Example

Try the following example below for better understanding.

<html>
     <head>
          <title>JavaScript String sub() Method</title>    
     </head>

     <body>
          <script  type = "text/Javascript">
               var  str = new String("Hello World");
               alert (str.sub(  ) );
          </script>
     </body>
</html>

Output

Below is the output of the above example.

<sub>Hello World</sub>

You can also read our tutorial post on: Getting Started with Python


String - sup() Method

This method causes a string to be displayed as a superscript, as if it were in a <sup> tag.

Syntax

The syntax for sup() method is as follows:

string.sup( )

Return Value

Returns the string having <sup> tag.

Example

Try the following example below for better understanding.

<html>
     <head>
          <title>JavaScript String sup() Method</title>    
     </head>

     <body>
          <script  type = "text/Javascript">
               var  str = new String("Hello World");
               alert (str.sup(  ) );
          </script>
     </body>
</html>

Output

Below is the output of the above example.

<sup>Hello World</sup>

Alright guys! we have finally come to the end of our tutorials on String Objects, its properties and methods. If my next tutorial post, we will be discussing about JavaScript Arrays Object. Stay tuned with so you don't get left behind.

Feel free to ask your questions via the comment box in any area you don't understand properly, i will make sure your questions are attended to as soon as possible. Don't forget to follow us on our various social media platforms to stay updated and also subscribe to our newsletter in other to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.

Post a Comment

Hello dear readers! Please kindly try your best to make sure your comments comply with our comment policy guidelines. You can visit our comment policy page to view these guidelines which are clearly stated. Thank you.
© 2023 ‧ WebDesignTutorialz. All rights reserved. Developed by Jago Desain