Home Javascript JavaScript strike method



JavaScript strike method
Posted on: April 3, 2006 at 12:00 AM
JavaScript strike() method can be used to strikethrough the string. It converts the string in the format like "Hello".

JavaScript strike method

     

JavaScript strike() method can be used to strikethrough the string. It converts the string in the format like "Hello". 

Syntax:

 string_object.strike();

Where string_object is the object at which we have to apply the strike() method. It returns the copy of string sandwiched between the pair of <strike> tag.

Description of code:

We will illustrate you the use of strike() method with a very simple example here. We have created an input text box which takes the string input by the user and as soon as we click on the button "Strike text", it calls the method strikeText() as defined in the JavaScript.

 function strikeText()
   {
  var textToStrike = document.getElementById('txt').value;
  document.getElementById('divId').innerHTML
  = textToStrike.strike(); 
  return true;
  }

First line of the function describes that we have created a variable "textToStrike" and thereafter we have taken the "divId" element's reference to show the string in strikethrough within "divId". Here is the full description code for "strikeMethodExample.html" as follows : 

<html>
 <head>
  <title>strike() method example</title>
   <script language="JavaScript">
     function strikeText()
     {
      var textToStrike = document.getElementById(
                           'txt').value;
      document.getElementById('divId').innerHTML
                          = textToStrike.strike(); 
      return true;
    }
   </script>
 </head>
<body>
<div style="background: #ff9900; width:'100%';"
      align="center">
  <font color="#0000ff" size="12pt">
    <b>strike() Example</b>
  </font>
</div>
<center>Insert any text 
 <input type="text" id="txt" /><br>
 <div id="divId" style="backgroud :#ccccff">
 </div>
 <input type="button" value="Strike text" 
  onClick="return strikeText();"/>
</center>
</body>
</html>

Output:

Input any text to apply strike() method over it.

As shown in output that it has stroked the text input.

Download Source Code

     

Related Tags for JavaScript strike method:


More Tutorials from this section

Ask Questions?    Discuss: JavaScript strike method  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.