[an error occurred while processing this directive]

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

                         

[an error occurred while processing this directive]